@sapphire/async-queue 1.1.9 β 1.2.0-next.365a53a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/index.global.js +66 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +67 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/dist/index.umd.js +0 -76
- package/dist/index.umd.js.map +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Ever needed a queue for a set of promises? This is the package for you.
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- Written in TypeScript
|
|
23
|
-
- Bundled with
|
|
23
|
+
- Bundled with esbuild so it can be used in NodeJS and browsers
|
|
24
24
|
- Offers CommonJS, ESM and UMD bundles
|
|
25
25
|
- Fully tested
|
|
26
26
|
|
|
@@ -56,7 +56,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
56
56
|
<!-- markdownlint-disable -->
|
|
57
57
|
<table>
|
|
58
58
|
<tr>
|
|
59
|
-
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=
|
|
59
|
+
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">π»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-favna" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">β οΈ</a></td>
|
|
60
60
|
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antonio RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">π»</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">β οΈ</a></td>
|
|
61
61
|
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">β οΈ</a></td>
|
|
62
62
|
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a> <a href="#userTesting-vladfrangu" title="User Testing">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">β οΈ</a></td>
|
|
@@ -78,9 +78,18 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
78
78
|
<td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">π§</a></td>
|
|
79
79
|
<td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">π»</a></td>
|
|
80
80
|
<td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">π</a></td>
|
|
81
|
-
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>
|
|
81
|
+
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">π»</a></td>
|
|
82
82
|
<td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">π»</a></td>
|
|
83
|
-
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">π</a></td>
|
|
83
|
+
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">π»</a></td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">π»</a></td>
|
|
87
|
+
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">π§</a></td>
|
|
88
|
+
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">π§</a></td>
|
|
89
|
+
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">π»</a></td>
|
|
90
|
+
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JΓ©rΓ©my de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">π»</a></td>
|
|
91
|
+
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">π»</a></td>
|
|
92
|
+
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">π»</a></td>
|
|
84
93
|
</tr>
|
|
85
94
|
</table>
|
|
86
95
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var SapphireAsyncQueue = (() => {
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module, copyDefault, desc) => {
|
|
14
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
22
|
+
return (module, temp) => {
|
|
23
|
+
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
|
|
24
|
+
};
|
|
25
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
26
|
+
var __publicField = (obj, key, value) => {
|
|
27
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
AsyncQueue: () => AsyncQueue
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/lib/AsyncQueue.ts
|
|
38
|
+
var AsyncQueue = class {
|
|
39
|
+
constructor() {
|
|
40
|
+
__publicField(this, "promises", []);
|
|
41
|
+
}
|
|
42
|
+
get remaining() {
|
|
43
|
+
return this.promises.length;
|
|
44
|
+
}
|
|
45
|
+
wait() {
|
|
46
|
+
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
47
|
+
let resolve;
|
|
48
|
+
const promise = new Promise((res) => {
|
|
49
|
+
resolve = res;
|
|
50
|
+
});
|
|
51
|
+
this.promises.push({
|
|
52
|
+
resolve,
|
|
53
|
+
promise
|
|
54
|
+
});
|
|
55
|
+
return next;
|
|
56
|
+
}
|
|
57
|
+
shift() {
|
|
58
|
+
const deferred = this.promises.shift();
|
|
59
|
+
if (typeof deferred !== "undefined")
|
|
60
|
+
deferred.resolve();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__name(AsyncQueue, "AsyncQueue");
|
|
64
|
+
return __toCommonJS(src_exports);
|
|
65
|
+
})();
|
|
66
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/AsyncQueue.ts"],"sourcesContent":["export * from './lib/AsyncQueue';\n","/**\n * The AsyncQueue class used to sequentialize burst requests\n */\nexport class AsyncQueue {\n\t/**\n\t * The remaining amount of queued promises\n\t */\n\tpublic get remaining(): number {\n\t\treturn this.promises.length;\n\t}\n\n\t/**\n\t * The promises array\n\t */\n\tprivate promises: InternalAsyncQueueDeferredPromise[] = [];\n\n\t/**\n\t * Waits for last promise and queues a new one\n\t * @example\n\t * ```typescript\n\t * const queue = new AsyncQueue();\n\t * async function request(url, options) {\n\t * await queue.wait();\n\t * try {\n\t * const result = await fetch(url, options);\n\t * // Do some operations with 'result'\n\t * } finally {\n\t * // Remove first entry from the queue and resolve for the next entry\n\t * queue.shift();\n\t * }\n\t * }\n\t *\n\t * request(someUrl1, someOptions1); // Will call fetch() immediately\n\t * request(someUrl2, someOptions2); // Will call fetch() after the first finished\n\t * request(someUrl3, someOptions3); // Will call fetch() after the second finished\n\t * ```\n\t */\n\tpublic wait(): Promise<void> {\n\t\tconst next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();\n\t\tlet resolve: () => void;\n\t\tconst promise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tthis.promises.push({\n\t\t\tresolve: resolve!,\n\t\t\tpromise\n\t\t});\n\n\t\treturn next;\n\t}\n\n\t/**\n\t * Frees the queue's lock for the next item to process\n\t */\n\tpublic shift(): void {\n\t\tconst deferred = this.promises.shift();\n\t\tif (typeof deferred !== 'undefined') deferred.resolve();\n\t}\n}\n\n/**\n * @internal\n */\ninterface InternalAsyncQueueDeferredPromise {\n\tresolve(): void;\n\tpromise: Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;;;ACGO,yBAAiB;AAAA,IAAjB,cAHP;AAcS,sCAAgD;AAAA;AAAA,QAP7C,YAAoB;AAC9B,aAAO,KAAK,SAAS;AAAA;AAAA,IA6Bf,OAAsB;AAC5B,YAAM,OAAO,KAAK,SAAS,SAAS,KAAK,SAAS,KAAK,SAAS,SAAS,GAAG,UAAU,QAAQ;AAC9F,UAAI;AACJ,YAAM,UAAU,IAAI,QAAc,CAAC,QAAQ;AAC1C,kBAAU;AAAA;AAGX,WAAK,SAAS,KAAK;AAAA,QAClB;AAAA,QACA;AAAA;AAGD,aAAO;AAAA;AAAA,IAMD,QAAc;AACpB,YAAM,WAAW,KAAK,SAAS;AAC/B,UAAI,OAAO,aAAa;AAAa,iBAAS;AAAA;AAAA;AAtDzC;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
22
|
+
return (module2, temp) => {
|
|
23
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
24
|
+
};
|
|
25
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
26
|
+
var __publicField = (obj, key, value) => {
|
|
27
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
2
30
|
|
|
3
|
-
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
AsyncQueue: () => AsyncQueue
|
|
35
|
+
});
|
|
4
36
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* queue.shift();
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
*
|
|
42
|
-
* request(someUrl1, someOptions1); // Will call fetch() immediately
|
|
43
|
-
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
|
|
44
|
-
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
wait() {
|
|
48
|
-
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
49
|
-
let resolve;
|
|
50
|
-
const promise = new Promise((res) => {
|
|
51
|
-
resolve = res;
|
|
52
|
-
});
|
|
53
|
-
this.promises.push({
|
|
54
|
-
resolve: resolve,
|
|
55
|
-
promise
|
|
56
|
-
});
|
|
57
|
-
return next;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Frees the queue's lock for the next item to process
|
|
61
|
-
*/
|
|
62
|
-
shift() {
|
|
63
|
-
const deferred = this.promises.shift();
|
|
64
|
-
if (typeof deferred !== 'undefined')
|
|
65
|
-
deferred.resolve();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.AsyncQueue = AsyncQueue;
|
|
70
|
-
//# sourceMappingURL=index.js.map
|
|
37
|
+
// src/lib/AsyncQueue.ts
|
|
38
|
+
var AsyncQueue = class {
|
|
39
|
+
constructor() {
|
|
40
|
+
__publicField(this, "promises", []);
|
|
41
|
+
}
|
|
42
|
+
get remaining() {
|
|
43
|
+
return this.promises.length;
|
|
44
|
+
}
|
|
45
|
+
wait() {
|
|
46
|
+
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
47
|
+
let resolve;
|
|
48
|
+
const promise = new Promise((res) => {
|
|
49
|
+
resolve = res;
|
|
50
|
+
});
|
|
51
|
+
this.promises.push({
|
|
52
|
+
resolve,
|
|
53
|
+
promise
|
|
54
|
+
});
|
|
55
|
+
return next;
|
|
56
|
+
}
|
|
57
|
+
shift() {
|
|
58
|
+
const deferred = this.promises.shift();
|
|
59
|
+
if (typeof deferred !== "undefined")
|
|
60
|
+
deferred.resolve();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__name(AsyncQueue, "AsyncQueue");
|
|
64
|
+
module.exports = __toCommonJS(src_exports);
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
AsyncQueue
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/AsyncQueue.ts"],"sourcesContent":["export * from './lib/AsyncQueue';\n","/**\n * The AsyncQueue class used to sequentialize burst requests\n */\nexport class AsyncQueue {\n\t/**\n\t * The remaining amount of queued promises\n\t */\n\tpublic get remaining(): number {\n\t\treturn this.promises.length;\n\t}\n\n\t/**\n\t * The promises array\n\t */\n\tprivate promises: InternalAsyncQueueDeferredPromise[] = [];\n\n\t/**\n\t * Waits for last promise and queues a new one\n\t * @example\n\t * ```typescript\n\t * const queue = new AsyncQueue();\n\t * async function request(url, options) {\n\t * await queue.wait();\n\t * try {\n\t * const result = await fetch(url, options);\n\t * // Do some operations with 'result'\n\t * } finally {\n\t * // Remove first entry from the queue and resolve for the next entry\n\t * queue.shift();\n\t * }\n\t * }\n\t *\n\t * request(someUrl1, someOptions1); // Will call fetch() immediately\n\t * request(someUrl2, someOptions2); // Will call fetch() after the first finished\n\t * request(someUrl3, someOptions3); // Will call fetch() after the second finished\n\t * ```\n\t */\n\tpublic wait(): Promise<void> {\n\t\tconst next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();\n\t\tlet resolve: () => void;\n\t\tconst promise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tthis.promises.push({\n\t\t\tresolve: resolve!,\n\t\t\tpromise\n\t\t});\n\n\t\treturn next;\n\t}\n\n\t/**\n\t * Frees the queue's lock for the next item to process\n\t */\n\tpublic shift(): void {\n\t\tconst deferred = this.promises.shift();\n\t\tif (typeof deferred !== 'undefined') deferred.resolve();\n\t}\n}\n\n/**\n * @internal\n */\ninterface InternalAsyncQueueDeferredPromise {\n\tresolve(): void;\n\tpromise: Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;;;ACGO,uBAAiB;AAAA,EAAjB,cAHP;AAcS,oCAAgD;AAAA;AAAA,MAP7C,YAAoB;AAC9B,WAAO,KAAK,SAAS;AAAA;AAAA,EA6Bf,OAAsB;AAC5B,UAAM,OAAO,KAAK,SAAS,SAAS,KAAK,SAAS,KAAK,SAAS,SAAS,GAAG,UAAU,QAAQ;AAC9F,QAAI;AACJ,UAAM,UAAU,IAAI,QAAc,CAAC,QAAQ;AAC1C,gBAAU;AAAA;AAGX,SAAK,SAAS,KAAK;AAAA,MAClB;AAAA,MACA;AAAA;AAGD,WAAO;AAAA;AAAA,EAMD,QAAc;AACpB,UAAM,WAAW,KAAK,SAAS;AAC/B,QAAI,OAAO,aAAa;AAAa,eAAS;AAAA;AAAA;AAtDzC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,66 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(this, "promises", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: []
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The remaining amount of queued promises
|
|
18
|
-
*/
|
|
19
|
-
get remaining() {
|
|
20
|
-
return this.promises.length;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Waits for last promise and queues a new one
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const queue = new AsyncQueue();
|
|
27
|
-
* async function request(url, options) {
|
|
28
|
-
* await queue.wait();
|
|
29
|
-
* try {
|
|
30
|
-
* const result = await fetch(url, options);
|
|
31
|
-
* // Do some operations with 'result'
|
|
32
|
-
* } finally {
|
|
33
|
-
* // Remove first entry from the queue and resolve for the next entry
|
|
34
|
-
* queue.shift();
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* request(someUrl1, someOptions1); // Will call fetch() immediately
|
|
39
|
-
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
|
|
40
|
-
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
wait() {
|
|
44
|
-
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
45
|
-
let resolve;
|
|
46
|
-
const promise = new Promise((res) => {
|
|
47
|
-
resolve = res;
|
|
48
|
-
});
|
|
49
|
-
this.promises.push({
|
|
50
|
-
resolve: resolve,
|
|
51
|
-
promise
|
|
52
|
-
});
|
|
53
|
-
return next;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Frees the queue's lock for the next item to process
|
|
57
|
-
*/
|
|
58
|
-
shift() {
|
|
59
|
-
const deferred = this.promises.shift();
|
|
60
|
-
if (typeof deferred !== 'undefined')
|
|
61
|
-
deferred.resolve();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
64
8
|
|
|
65
|
-
|
|
66
|
-
|
|
9
|
+
// src/lib/AsyncQueue.ts
|
|
10
|
+
var AsyncQueue = class {
|
|
11
|
+
constructor() {
|
|
12
|
+
__publicField(this, "promises", []);
|
|
13
|
+
}
|
|
14
|
+
get remaining() {
|
|
15
|
+
return this.promises.length;
|
|
16
|
+
}
|
|
17
|
+
wait() {
|
|
18
|
+
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
19
|
+
let resolve;
|
|
20
|
+
const promise = new Promise((res) => {
|
|
21
|
+
resolve = res;
|
|
22
|
+
});
|
|
23
|
+
this.promises.push({
|
|
24
|
+
resolve,
|
|
25
|
+
promise
|
|
26
|
+
});
|
|
27
|
+
return next;
|
|
28
|
+
}
|
|
29
|
+
shift() {
|
|
30
|
+
const deferred = this.promises.shift();
|
|
31
|
+
if (typeof deferred !== "undefined")
|
|
32
|
+
deferred.resolve();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__name(AsyncQueue, "AsyncQueue");
|
|
36
|
+
export {
|
|
37
|
+
AsyncQueue
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/lib/AsyncQueue.ts"],"sourcesContent":["/**\n * The AsyncQueue class used to sequentialize burst requests\n */\nexport class AsyncQueue {\n\t/**\n\t * The remaining amount of queued promises\n\t */\n\tpublic get remaining(): number {\n\t\treturn this.promises.length;\n\t}\n\n\t/**\n\t * The promises array\n\t */\n\tprivate promises: InternalAsyncQueueDeferredPromise[] = [];\n\n\t/**\n\t * Waits for last promise and queues a new one\n\t * @example\n\t * ```typescript\n\t * const queue = new AsyncQueue();\n\t * async function request(url, options) {\n\t * await queue.wait();\n\t * try {\n\t * const result = await fetch(url, options);\n\t * // Do some operations with 'result'\n\t * } finally {\n\t * // Remove first entry from the queue and resolve for the next entry\n\t * queue.shift();\n\t * }\n\t * }\n\t *\n\t * request(someUrl1, someOptions1); // Will call fetch() immediately\n\t * request(someUrl2, someOptions2); // Will call fetch() after the first finished\n\t * request(someUrl3, someOptions3); // Will call fetch() after the second finished\n\t * ```\n\t */\n\tpublic wait(): Promise<void> {\n\t\tconst next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();\n\t\tlet resolve: () => void;\n\t\tconst promise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tthis.promises.push({\n\t\t\tresolve: resolve!,\n\t\t\tpromise\n\t\t});\n\n\t\treturn next;\n\t}\n\n\t/**\n\t * Frees the queue's lock for the next item to process\n\t */\n\tpublic shift(): void {\n\t\tconst deferred = this.promises.shift();\n\t\tif (typeof deferred !== 'undefined') deferred.resolve();\n\t}\n}\n\n/**\n * @internal\n */\ninterface InternalAsyncQueueDeferredPromise {\n\tresolve(): void;\n\tpromise: Promise<void>;\n}\n"],"mappings":";;;;;;;;;AAGO,uBAAiB;AAAA,EAAjB,cAHP;AAcS,oCAAgD;AAAA;AAAA,MAP7C,YAAoB;AAC9B,WAAO,KAAK,SAAS;AAAA;AAAA,EA6Bf,OAAsB;AAC5B,UAAM,OAAO,KAAK,SAAS,SAAS,KAAK,SAAS,KAAK,SAAS,SAAS,GAAG,UAAU,QAAQ;AAC9F,QAAI;AACJ,UAAM,UAAU,IAAI,QAAc,CAAC,QAAQ;AAC1C,gBAAU;AAAA;AAGX,SAAK,SAAS,KAAK;AAAA,MAClB;AAAA,MACA;AAAA;AAGD,WAAO;AAAA;AAAA,EAMD,QAAc;AACpB,UAAM,WAAW,KAAK,SAAS;AAC/B,QAAI,OAAO,aAAa;AAAa,eAAS;AAAA;AAAA;AAtDzC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/async-queue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-next.365a53a.0",
|
|
4
4
|
"description": "Sequential asynchronous lock-based queue for promises",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.mjs",
|
|
9
|
-
"browser": "dist/index.
|
|
10
|
-
"unpkg": "dist/index.
|
|
9
|
+
"browser": "dist/index.global.js",
|
|
10
|
+
"unpkg": "dist/index.global.js",
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
12
|
"typedocMain": "src/index.ts",
|
|
13
13
|
"exports": {
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "jest",
|
|
21
21
|
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
22
|
-
"build": "
|
|
23
|
-
"start": "yarn build -w",
|
|
22
|
+
"build": "tsup && tsc -b src",
|
|
24
23
|
"prepublishOnly": "yarn build"
|
|
25
24
|
},
|
|
26
25
|
"repository": {
|
|
@@ -52,5 +51,5 @@
|
|
|
52
51
|
"publishConfig": {
|
|
53
52
|
"access": "public"
|
|
54
53
|
},
|
|
55
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "365a53a5517a01a0926cf28a83c96b63f32ed9f8"
|
|
56
55
|
}
|
package/dist/index.umd.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SapphireAsyncQueue = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The AsyncQueue class used to sequentialize burst requests
|
|
9
|
-
*/
|
|
10
|
-
class AsyncQueue {
|
|
11
|
-
constructor() {
|
|
12
|
-
/**
|
|
13
|
-
* The promises array
|
|
14
|
-
*/
|
|
15
|
-
Object.defineProperty(this, "promises", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: []
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The remaining amount of queued promises
|
|
24
|
-
*/
|
|
25
|
-
get remaining() {
|
|
26
|
-
return this.promises.length;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Waits for last promise and queues a new one
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const queue = new AsyncQueue();
|
|
33
|
-
* async function request(url, options) {
|
|
34
|
-
* await queue.wait();
|
|
35
|
-
* try {
|
|
36
|
-
* const result = await fetch(url, options);
|
|
37
|
-
* // Do some operations with 'result'
|
|
38
|
-
* } finally {
|
|
39
|
-
* // Remove first entry from the queue and resolve for the next entry
|
|
40
|
-
* queue.shift();
|
|
41
|
-
* }
|
|
42
|
-
* }
|
|
43
|
-
*
|
|
44
|
-
* request(someUrl1, someOptions1); // Will call fetch() immediately
|
|
45
|
-
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
|
|
46
|
-
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
wait() {
|
|
50
|
-
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
|
51
|
-
let resolve;
|
|
52
|
-
const promise = new Promise((res) => {
|
|
53
|
-
resolve = res;
|
|
54
|
-
});
|
|
55
|
-
this.promises.push({
|
|
56
|
-
resolve: resolve,
|
|
57
|
-
promise
|
|
58
|
-
});
|
|
59
|
-
return next;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Frees the queue's lock for the next item to process
|
|
63
|
-
*/
|
|
64
|
-
shift() {
|
|
65
|
-
const deferred = this.promises.shift();
|
|
66
|
-
if (typeof deferred !== 'undefined')
|
|
67
|
-
deferred.resolve();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
exports.AsyncQueue = AsyncQueue;
|
|
72
|
-
|
|
73
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
74
|
-
|
|
75
|
-
}));
|
|
76
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/lib/AsyncQueue.ts"],"sourcesContent":["/**\n * The AsyncQueue class used to sequentialize burst requests\n */\nexport class AsyncQueue {\n\t/**\n\t * The remaining amount of queued promises\n\t */\n\tpublic get remaining(): number {\n\t\treturn this.promises.length;\n\t}\n\n\t/**\n\t * The promises array\n\t */\n\tprivate promises: InternalAsyncQueueDeferredPromise[] = [];\n\n\t/**\n\t * Waits for last promise and queues a new one\n\t * @example\n\t * ```typescript\n\t * const queue = new AsyncQueue();\n\t * async function request(url, options) {\n\t * await queue.wait();\n\t * try {\n\t * const result = await fetch(url, options);\n\t * // Do some operations with 'result'\n\t * } finally {\n\t * // Remove first entry from the queue and resolve for the next entry\n\t * queue.shift();\n\t * }\n\t * }\n\t *\n\t * request(someUrl1, someOptions1); // Will call fetch() immediately\n\t * request(someUrl2, someOptions2); // Will call fetch() after the first finished\n\t * request(someUrl3, someOptions3); // Will call fetch() after the second finished\n\t * ```\n\t */\n\tpublic wait(): Promise<void> {\n\t\tconst next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();\n\t\tlet resolve: () => void;\n\t\tconst promise = new Promise<void>((res) => {\n\t\t\tresolve = res;\n\t\t});\n\n\t\tthis.promises.push({\n\t\t\tresolve: resolve!,\n\t\t\tpromise\n\t\t});\n\n\t\treturn next;\n\t}\n\n\t/**\n\t * Frees the queue's lock for the next item to process\n\t */\n\tpublic shift(): void {\n\t\tconst deferred = this.promises.shift();\n\t\tif (typeof deferred !== 'undefined') deferred.resolve();\n\t}\n}\n\n/**\n * @internal\n */\ninterface InternalAsyncQueueDeferredPromise {\n\tresolve(): void;\n\tpromise: Promise<void>;\n}\n"],"names":[],"mappings":";;;;;;CAAA;;;OAGa,UAAU;KAAvB;;;;SAWC;;;;oBAAwD,EAAE;YAAC;MA6C3D;;;;KApDA,IAAW,SAAS;SACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;MAC5B;;;;;;;;;;;;;;;;;;;;;;KA4BM,IAAI;SACV,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;SACxG,IAAI,OAAmB,CAAC;SACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,GAAG;aACrC,OAAO,GAAG,GAAG,CAAC;UACd,CAAC,CAAC;SAEH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;aAClB,OAAO,EAAE,OAAQ;aACjB,OAAO;UACP,CAAC,CAAC;SAEH,OAAO,IAAI,CAAC;MACZ;;;;KAKM,KAAK;SACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;SACvC,IAAI,OAAO,QAAQ,KAAK,WAAW;aAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;MACxD;;;;;;;;;;;"}
|