@sapphire/async-queue 1.1.5-next.8032624d.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/LICENSE.md ADDED
@@ -0,0 +1,24 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright © `2020` `The Sapphire Community and its contributors`
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation
7
+ files (the “Software”), to deal in the Software without
8
+ restriction, including without limitation the rights to use,
9
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following
12
+ conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ <div align="center">
2
+
3
+ ![Sapphire Logo](https://cdn.skyra.pw/gh-assets/sapphire-banner.png)
4
+
5
+ # @sapphire/async-queue
6
+
7
+ **Sequential asynchronous lock-based queue for promises.**
8
+
9
+ [![GitHub](https://img.shields.io/github/license/sapphiredev/utilities)](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
10
+ [![codecov](https://codecov.io/gh/sapphiredev/utilities/branch/main/graph/badge.svg?token=OEGIV6RFDO)](https://codecov.io/gh/sapphiredev/utilities)
11
+ [![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/async-queue?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/async-queue)
12
+ [![npm](https://img.shields.io/npm/v/@sapphire/async-queue?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/async-queue)
13
+
14
+ </div>
15
+
16
+ ## Description
17
+
18
+ Ever needed a queue for a set of promises? This is the package for you.
19
+
20
+ ## Features
21
+
22
+ - Written in TypeScript
23
+ - Bundled with Rollup so it can be used in NodeJS and browsers
24
+ - Offers CommonJS, ESM and UMD bundles
25
+ - Fully tested
26
+
27
+ ## Installation
28
+
29
+ You can use the following command to install this package, or replace `npm install` with your package manager of choice.
30
+
31
+ ```sh
32
+ npm install @sapphire/async-queue
33
+ ```
34
+
35
+ ---
36
+
37
+ ## API Documentation
38
+
39
+ For the full API documentation please refer to the TypeDoc generated [documentation](https://sapphiredev.github.io/utilities/modules/_sapphire_async_queue.html).
40
+
41
+ ## Buy us some doughnuts
42
+
43
+ Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
44
+
45
+ We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
46
+
47
+ | Donate With | Address |
48
+ | :-------------: | :-------------------------------------------------: |
49
+ | Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
50
+ | Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
51
+ | Patreon | [Click Here](https://sapphirejs.dev/patreon) |
52
+ | PayPal | [Click Here](https://sapphirejs.dev/paypal) |
53
+
54
+ ## Contributors ✨
55
+
56
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
57
+
58
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
59
+ <!-- prettier-ignore-start -->
60
+ <!-- markdownlint-disable -->
61
+ <table>
62
+ <tr>
63
+ <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>
64
+ <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>
65
+ <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>
66
+ <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>
67
+ <td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">💻</a> <a href="#projectManagement-Stitch07" title="Project Management">📆</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
68
+ <td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">🚧</a></td>
69
+ <td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">📖</a></td>
70
+ </tr>
71
+ <tr>
72
+ <td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">📖</a></td>
73
+ <td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">🐛</a></td>
74
+ <td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">💻</a></td>
75
+ <td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
76
+ <td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">💻</a></td>
77
+ <td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">📖</a></td>
78
+ <td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">💻</a></td>
79
+ </tr>
80
+ <tr>
81
+ <td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">💻</a></td>
82
+ <td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">📖</a></td>
83
+ <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>
84
+ <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>
85
+ <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>
86
+ </tr>
87
+ </table>
88
+
89
+ <!-- markdownlint-restore -->
90
+ <!-- prettier-ignore-end -->
91
+
92
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
93
+
94
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
@@ -0,0 +1,2 @@
1
+ export * from './lib/AsyncQueue';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * The AsyncQueue class used to sequentialize burst requests
7
+ */
8
+ class AsyncQueue {
9
+ constructor() {
10
+ /**
11
+ * The promises array
12
+ */
13
+ Object.defineProperty(this, "promises", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: []
18
+ });
19
+ }
20
+ /**
21
+ * The remaining amount of queued promises
22
+ */
23
+ get remaining() {
24
+ return this.promises.length;
25
+ }
26
+ /**
27
+ * Waits for last promise and queues a new one
28
+ * @example
29
+ * ```
30
+ * const queue = new AsyncQueue();
31
+ * async function request(url, options) {
32
+ * await queue.wait();
33
+ * try {
34
+ * const result = await fetch(url, options);
35
+ * // Do some operations with 'result'
36
+ * } finally {
37
+ * // Remove first entry from the queue and resolve for the next entry
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.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 * ```\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":";;;;AAAA;;;MAGa,UAAU;IAAvB;;;;QAWC;;;;mBAAwD,EAAE;WAAC;KA6C3D;;;;IApDA,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;KAC5B;;;;;;;;;;;;;;;;;;;;;;IA4BM,IAAI;QACV,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;QACxG,IAAI,OAAmB,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,GAAG;YACrC,OAAO,GAAG,GAAG,CAAC;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,OAAO,EAAE,OAAQ;YACjB,OAAO;SACP,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;KACZ;;;;IAKM,KAAK;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;KACxD;;;;;"}
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The AsyncQueue class used to sequentialize burst requests
3
+ */
4
+ class AsyncQueue {
5
+ constructor() {
6
+ /**
7
+ * The promises array
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
+ * ```
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
+ }
64
+
65
+ export { AsyncQueue };
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","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 * ```\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":"AAAA;;;MAGa,UAAU;IAAvB;;;;QAWC;;;;mBAAwD,EAAE;WAAC;KA6C3D;;;;IApDA,IAAW,SAAS;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;KAC5B;;;;;;;;;;;;;;;;;;;;;;IA4BM,IAAI;QACV,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;QACxG,IAAI,OAAmB,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,GAAG;YACrC,OAAO,GAAG,GAAG,CAAC;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,OAAO,EAAE,OAAQ;YACjB,OAAO;SACP,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;KACZ;;;;IAKM,KAAK;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;KACxD;;;;;"}
@@ -0,0 +1,76 @@
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
+ * ```
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
@@ -0,0 +1 @@
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 * ```\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;;;;;;;;;;;"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The AsyncQueue class used to sequentialize burst requests
3
+ */
4
+ export declare class AsyncQueue {
5
+ /**
6
+ * The remaining amount of queued promises
7
+ */
8
+ get remaining(): number;
9
+ /**
10
+ * The promises array
11
+ */
12
+ private promises;
13
+ /**
14
+ * Waits for last promise and queues a new one
15
+ * @example
16
+ * ```
17
+ * const queue = new AsyncQueue();
18
+ * async function request(url, options) {
19
+ * await queue.wait();
20
+ * try {
21
+ * const result = await fetch(url, options);
22
+ * // Do some operations with 'result'
23
+ * } finally {
24
+ * // Remove first entry from the queue and resolve for the next entry
25
+ * queue.shift();
26
+ * }
27
+ * }
28
+ *
29
+ * request(someUrl1, someOptions1); // Will call fetch() immediately
30
+ * request(someUrl2, someOptions2); // Will call fetch() after the first finished
31
+ * request(someUrl3, someOptions3); // Will call fetch() after the second finished
32
+ * ```
33
+ */
34
+ wait(): Promise<void>;
35
+ /**
36
+ * Frees the queue's lock for the next item to process
37
+ */
38
+ shift(): void;
39
+ }
40
+ //# sourceMappingURL=AsyncQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncQueue.d.ts","sourceRoot":"","sources":["../../src/lib/AsyncQueue.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAU;IACtB;;OAEG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED;;OAEG;IACH,OAAO,CAAC,QAAQ,CAA2C;IAE3D;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B;;OAEG;IACI,KAAK,IAAI,IAAI;CAIpB"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@sapphire/async-queue",
3
+ "version": "1.1.5-next.8032624d.0",
4
+ "description": "Sequential asynchronous lock-based queue for promises",
5
+ "author": "@sapphire",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
9
+ "browser": "dist/index.umd.js",
10
+ "unpkg": "dist/index.umd.js",
11
+ "types": "dist/index.d.ts",
12
+ "typedocMain": "src/index.ts",
13
+ "exports": {
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ },
17
+ "sideEffects": false,
18
+ "homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/async-queue",
19
+ "scripts": {
20
+ "test": "jest",
21
+ "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
22
+ "build": "rollup -c",
23
+ "start": "yarn build -w",
24
+ "prepublishOnly": "yarn build"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/sapphiredev/utilities.git",
29
+ "directory": "packages/async-queue"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "!dist/*.tsbuildinfo"
34
+ ],
35
+ "engines": {
36
+ "node": ">=14",
37
+ "npm": ">=6"
38
+ },
39
+ "keywords": [
40
+ "@sapphire/async-queue",
41
+ "bot",
42
+ "typescript",
43
+ "ts",
44
+ "yarn",
45
+ "discord",
46
+ "sapphire",
47
+ "standalone"
48
+ ],
49
+ "bugs": {
50
+ "url": "https://github.com/sapphiredev/utilities/issues"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "gitHead": "8032624d34a018b47ba3d2b9c06bd6572849c925"
56
+ }