@alwatr/async-queue 5.5.29 → 6.0.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/dist/main.js ADDED
@@ -0,0 +1,5 @@
1
+ /* 📦 @alwatr/async-queue v6.0.0 */
2
+ import{newFlatomise as B}from"@alwatr/flatomise";class C{queue__={};async push(b,j){let g=B(),z=this.queue__[b];this.queue__[b]=g.promise;try{await z}catch(D){}return setTimeout(()=>{j().then(g.resolve,g.reject).then(()=>{if(this.queue__[b]===g.promise)delete this.queue__[b]})},0),g.promise}isRunning(b){return this.queue__[b]!==void 0}waitForFinish(b){return this.queue__[b]??Promise.resolve()}waitForAllFinish(){return Promise.all(Object.values(this.queue__))}}export{C as AsyncQueue};
3
+
4
+ //# debugId=D6860014B841F55064756E2164756E21
5
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": [
5
+ "import {newFlatomise} from '@alwatr/flatomise';\n\nimport type {} from '@alwatr/type-helper';\n\n/**\n * A queue that executes async tasks in order like mutex and semaphore methodology\n *\n * @example\n * ```ts\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * }\n * ```\n */\nexport class AsyncQueue {\n /**\n * A record of task IDs and their corresponding last queued task promises.\n */\n private queue__: DictionaryOpt<Promise<unknown>> = {};\n\n /**\n * Push a async task to the queue.\n *\n * @param taskId task id\n * @param task async task\n * @returns A promise that resolves when the task is done.\n *\n * @example\n * ```typescript\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * ```\n */\n public async push<T>(taskId: string, task: () => Promise<T>): Promise<T> {\n const flatomise = newFlatomise<T>();\n\n const previousTaskPromise = this.queue__[taskId];\n this.queue__[taskId] = flatomise.promise;\n\n try {\n await previousTaskPromise;\n }\n catch (_e) {\n // ignore\n }\n\n setTimeout(() => {\n task()\n .then(flatomise.resolve, flatomise.reject)\n .then(() => {\n if (this.queue__[taskId] === flatomise.promise) {\n delete this.queue__[taskId];\n }\n });\n }, 0);\n\n return flatomise.promise;\n }\n\n /**\n * Check if the task running in the queue.\n *\n * @param taskId task id\n * @returns true if the task is running, otherwise false.\n * @example\n * ```typescript\n * if (queue.isRunning('longTaskId')) {\n * // ...\n * }\n * ```\n */\n public isRunning(taskId: string): boolean {\n return this.queue__[taskId] !== undefined;\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n *\n * @param taskId task id\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForFinish('longTaskId');\n * ```\n */\n public waitForFinish(taskId: string): Promise<unknown> {\n return this.queue__[taskId] ?? Promise.resolve();\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForAllFinish();\n * ```\n */\n public waitForAllFinish(): Promise<unknown[]> {\n return Promise.all(Object.values(this.queue__));\n }\n}\n"
6
+ ],
7
+ "mappings": ";AAAA,uBAAQ,0BAkBD,MAAM,CAAW,CAId,QAA2C,CAAC,OAmBvC,KAAO,CAAC,EAAgB,EAAoC,CACvE,IAAM,EAAY,EAAgB,EAE5B,EAAsB,KAAK,QAAQ,GACzC,KAAK,QAAQ,GAAU,EAAU,QAEjC,GAAI,CACF,MAAM,EAER,MAAO,EAAI,EAcX,OAVA,WAAW,IAAM,CACf,EAAK,EACF,KAAK,EAAU,QAAS,EAAU,MAAM,EACxC,KAAK,IAAM,CACV,GAAI,KAAK,QAAQ,KAAY,EAAU,QACrC,OAAO,KAAK,QAAQ,GAEvB,GACF,CAAC,EAEG,EAAU,QAeZ,SAAS,CAAC,EAAyB,CACxC,OAAO,KAAK,QAAQ,KAAY,OAa3B,aAAa,CAAC,EAAkC,CACrD,OAAO,KAAK,QAAQ,IAAW,QAAQ,QAAQ,EAW1C,gBAAgB,EAAuB,CAC5C,OAAO,QAAQ,IAAI,OAAO,OAAO,KAAK,OAAO,CAAC,EAElD",
8
+ "debugId": "D6860014B841F55064756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@alwatr/async-queue",
3
3
  "description": "A queue that executes async tasks in order like mutex and semaphore methodology for javascript and typescript.",
4
- "version": "5.5.29",
4
+ "version": "6.0.0",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "dependencies": {
8
- "@alwatr/flatomise": "5.5.29"
8
+ "@alwatr/flatomise": "6.0.0"
9
9
  },
10
10
  "devDependencies": {
11
- "@alwatr/nano-build": "6.4.2",
12
- "@alwatr/prettier-config": "6.0.2",
13
- "@alwatr/tsconfig-base": "6.0.4",
14
- "@alwatr/type-helper": "7.0.2",
11
+ "@alwatr/nano-build": "7.0.0",
12
+ "@alwatr/prettier-config": "7.0.0",
13
+ "@alwatr/tsconfig-base": "7.0.0",
14
+ "@alwatr/type-helper": "8.0.0",
15
15
  "typescript": "^5.9.3"
16
16
  },
17
17
  "exports": {
18
18
  ".": {
19
19
  "types": "./dist/main.d.ts",
20
- "import": "./dist/main.mjs",
21
- "require": "./dist/main.cjs"
20
+ "default": "./dist/main.js"
22
21
  }
23
22
  },
24
23
  "files": [
25
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
24
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
25
+ "README.md",
26
26
  "LICENSE",
27
27
  "!demo/**/*",
28
28
  "!**/*.test.js"
@@ -54,8 +54,6 @@
54
54
  "utils"
55
55
  ],
56
56
  "license": "MPL-2.0",
57
- "main": "./dist/main.cjs",
58
- "module": "./dist/main.mjs",
59
57
  "prettier": "@alwatr/prettier-config",
60
58
  "publishConfig": {
61
59
  "access": "public"
@@ -68,14 +66,14 @@
68
66
  "scripts": {
69
67
  "b": "bun run build",
70
68
  "build": "bun run build:ts && bun run build:es",
71
- "build:es": "nano-build --preset=module",
69
+ "build:es": "nano-build --preset=module src/main.ts",
72
70
  "build:ts": "tsc --build",
73
71
  "c": "bun run clean",
74
72
  "cb": "bun run clean && bun run build",
75
73
  "clean": "rm -rfv dist *.tsbuildinfo",
76
- "d": "bun run build:es && bun --enable-source-maps --trace-warnings",
74
+ "d": "bun run build:es && bun",
77
75
  "t": "bun run test",
78
- "test": "echo test-skipped",
76
+ "test": "bun test",
79
77
  "w": "bun run watch",
80
78
  "watch": "bun run watch:ts & bun run watch:es",
81
79
  "watch:es": "bun run build:es --watch",
@@ -83,5 +81,5 @@
83
81
  },
84
82
  "type": "module",
85
83
  "types": "./dist/main.d.ts",
86
- "gitHead": "c3889e3756b0a0f9b935a1b702a1373ac52cb379"
84
+ "gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
87
85
  }
package/src/main.ts ADDED
@@ -0,0 +1,109 @@
1
+ import {newFlatomise} from '@alwatr/flatomise';
2
+
3
+ import type {} from '@alwatr/type-helper';
4
+
5
+ /**
6
+ * A queue that executes async tasks in order like mutex and semaphore methodology
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const queue = new AsyncQueue();
11
+ *
12
+ * function longTask() {
13
+ * queue.push('longTaskId', async () => {
14
+ * // ...
15
+ * });
16
+ * }
17
+ * ```
18
+ */
19
+ export class AsyncQueue {
20
+ /**
21
+ * A record of task IDs and their corresponding last queued task promises.
22
+ */
23
+ private queue__: DictionaryOpt<Promise<unknown>> = {};
24
+
25
+ /**
26
+ * Push a async task to the queue.
27
+ *
28
+ * @param taskId task id
29
+ * @param task async task
30
+ * @returns A promise that resolves when the task is done.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const queue = new AsyncQueue();
35
+ *
36
+ * function longTask() {
37
+ * queue.push('longTaskId', async () => {
38
+ * // ...
39
+ * });
40
+ * ```
41
+ */
42
+ public async push<T>(taskId: string, task: () => Promise<T>): Promise<T> {
43
+ const flatomise = newFlatomise<T>();
44
+
45
+ const previousTaskPromise = this.queue__[taskId];
46
+ this.queue__[taskId] = flatomise.promise;
47
+
48
+ try {
49
+ await previousTaskPromise;
50
+ }
51
+ catch (_e) {
52
+ // ignore
53
+ }
54
+
55
+ setTimeout(() => {
56
+ task()
57
+ .then(flatomise.resolve, flatomise.reject)
58
+ .then(() => {
59
+ if (this.queue__[taskId] === flatomise.promise) {
60
+ delete this.queue__[taskId];
61
+ }
62
+ });
63
+ }, 0);
64
+
65
+ return flatomise.promise;
66
+ }
67
+
68
+ /**
69
+ * Check if the task running in the queue.
70
+ *
71
+ * @param taskId task id
72
+ * @returns true if the task is running, otherwise false.
73
+ * @example
74
+ * ```typescript
75
+ * if (queue.isRunning('longTaskId')) {
76
+ * // ...
77
+ * }
78
+ * ```
79
+ */
80
+ public isRunning(taskId: string): boolean {
81
+ return this.queue__[taskId] !== undefined;
82
+ }
83
+
84
+ /**
85
+ * Wait for the all tasks in the queue to finish.
86
+ *
87
+ * @param taskId task id
88
+ * @returns A promise that resolves when all tasks are done.
89
+ * @example
90
+ * ```typescript
91
+ * await queue.waitForFinish('longTaskId');
92
+ * ```
93
+ */
94
+ public waitForFinish(taskId: string): Promise<unknown> {
95
+ return this.queue__[taskId] ?? Promise.resolve();
96
+ }
97
+
98
+ /**
99
+ * Wait for the all tasks in the queue to finish.
100
+ * @returns A promise that resolves when all tasks are done.
101
+ * @example
102
+ * ```typescript
103
+ * await queue.waitForAllFinish();
104
+ * ```
105
+ */
106
+ public waitForAllFinish(): Promise<unknown[]> {
107
+ return Promise.all(Object.values(this.queue__));
108
+ }
109
+ }
package/CHANGELOG.md DELETED
@@ -1,407 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [5.5.29](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.28...@alwatr/async-queue@5.5.29) (2026-03-16)
7
-
8
- ### 🔨 Code Refactoring
9
-
10
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
11
-
12
- ## [5.5.28](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.27...@alwatr/async-queue@5.5.28) (2026-02-18)
13
-
14
- **Note:** Version bump only for package @alwatr/async-queue
15
-
16
- ## [5.5.27](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.26...@alwatr/async-queue@5.5.27) (2025-12-23)
17
-
18
- **Note:** Version bump only for package @alwatr/async-queue
19
-
20
- ## [5.5.26](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.25...@alwatr/async-queue@5.5.26) (2025-12-13)
21
-
22
- **Note:** Version bump only for package @alwatr/async-queue
23
-
24
- ## [5.5.25](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.24...@alwatr/async-queue@5.5.25) (2025-12-10)
25
-
26
- **Note:** Version bump only for package @alwatr/async-queue
27
-
28
- ## [5.5.24](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.23...@alwatr/async-queue@5.5.24) (2025-11-18)
29
-
30
- ### 🐛 Bug Fixes
31
-
32
- * add type imports from @alwatr/nano-build and @alwatr/type-helper across multiple packages ([5ab7f15](https://github.com/Alwatr/nanolib/commit/5ab7f159ba57788bf8df40fa96a3027f589d5a77))
33
-
34
- ### 🔨 Code Refactoring
35
-
36
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
37
-
38
- ## [5.5.23](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.22...@alwatr/async-queue@5.5.23) (2025-11-15)
39
-
40
- **Note:** Version bump only for package @alwatr/async-queue
41
-
42
- ## [5.5.22](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.21...@alwatr/async-queue@5.5.22) (2025-11-15)
43
-
44
- **Note:** Version bump only for package @alwatr/async-queue
45
-
46
- ## [5.5.21](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.20...@alwatr/async-queue@5.5.21) (2025-11-04)
47
-
48
- **Note:** Version bump only for package @alwatr/async-queue
49
-
50
- ## [5.5.20](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.19...@alwatr/async-queue@5.5.20) (2025-10-06)
51
-
52
- ### 🔗 Dependencies update
53
-
54
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
55
-
56
- ## [5.5.19](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.18...@alwatr/async-queue@5.5.19) (2025-09-27)
57
-
58
- ### 🧹 Miscellaneous Chores
59
-
60
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
61
-
62
- ## [5.5.18](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.17...@alwatr/async-queue@5.5.18) (2025-09-22)
63
-
64
- **Note:** Version bump only for package @alwatr/async-queue
65
-
66
- ## [5.5.17](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.16...@alwatr/async-queue@5.5.17) (2025-09-22)
67
-
68
- **Note:** Version bump only for package @alwatr/async-queue
69
-
70
- ## [5.5.16](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.15...@alwatr/async-queue@5.5.16) (2025-09-21)
71
-
72
- **Note:** Version bump only for package @alwatr/async-queue
73
-
74
- ## [5.5.15](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.14...@alwatr/async-queue@5.5.15) (2025-09-20)
75
-
76
- **Note:** Version bump only for package @alwatr/async-queue
77
-
78
- ## [5.5.14](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.13...@alwatr/async-queue@5.5.14) (2025-09-19)
79
-
80
- **Note:** Version bump only for package @alwatr/async-queue
81
-
82
- ## [5.5.13](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.12...@alwatr/async-queue@5.5.13) (2025-09-15)
83
-
84
- **Note:** Version bump only for package @alwatr/async-queue
85
-
86
- ## [5.5.12](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.11...@alwatr/async-queue@5.5.12) (2025-09-13)
87
-
88
- **Note:** Version bump only for package @alwatr/async-queue
89
-
90
- ## [5.5.11](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.10...@alwatr/async-queue@5.5.11) (2025-09-13)
91
-
92
- ### 🧹 Miscellaneous Chores
93
-
94
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
95
-
96
- ## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.9...@alwatr/async-queue@5.5.10) (2025-09-09)
97
-
98
- ### 🧹 Miscellaneous Chores
99
-
100
- * remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
101
-
102
- ## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.8...@alwatr/async-queue@5.5.9) (2025-09-06)
103
-
104
- **Note:** Version bump only for package @alwatr/async-queue
105
-
106
- ## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.7...@alwatr/async-queue@5.5.8) (2025-09-05)
107
-
108
- ### 🔗 Dependencies update
109
-
110
- * update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
111
-
112
- ## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.6...@alwatr/async-queue@5.5.7) (2025-09-01)
113
-
114
- ### 🔗 Dependencies update
115
-
116
- * update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
117
-
118
- ## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.5...@alwatr/async-queue@5.5.6) (2025-08-23)
119
-
120
- **Note:** Version bump only for package @alwatr/async-queue
121
-
122
- ## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.3...@alwatr/async-queue@5.5.5) (2025-08-23)
123
-
124
- ### 🐛 Bug Fixes
125
-
126
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
127
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
128
-
129
- ### 🔨 Code Refactoring
130
-
131
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
132
-
133
- ### 🧹 Miscellaneous Chores
134
-
135
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
136
-
137
- ### 🔗 Dependencies update
138
-
139
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
140
-
141
- ## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.3...@alwatr/async-queue@5.5.4) (2025-08-23)
142
-
143
- ### Code Refactoring
144
-
145
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
146
-
147
- ## <small>5.5.3 (2025-04-15)</small>
148
-
149
- **Note:** Version bump only for package @alwatr/async-queue
150
-
151
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.1...@alwatr/async-queue@5.5.2) (2025-04-01)
152
-
153
- **Note:** Version bump only for package @alwatr/async-queue
154
-
155
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.0...@alwatr/async-queue@5.5.1) (2025-03-18)
156
-
157
- **Note:** Version bump only for package @alwatr/async-queue
158
-
159
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.4.0...@alwatr/async-queue@5.5.0) (2025-03-06)
160
-
161
- ### Miscellaneous Chores
162
-
163
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
164
-
165
- ### Dependencies update
166
-
167
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
168
-
169
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.8...@alwatr/async-queue@5.4.0) (2025-02-18)
170
-
171
- ## 5.3.0 (2025-02-03)
172
-
173
- ### Miscellaneous Chores
174
-
175
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
176
-
177
- ### Dependencies update
178
-
179
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
180
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
181
-
182
- ## 5.0.0 (2024-11-02)
183
-
184
- ### ⚠ BREAKING CHANGES
185
-
186
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
187
-
188
- ### Code Refactoring
189
-
190
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
191
-
192
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
193
-
194
- ### Miscellaneous Chores
195
-
196
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
197
-
198
- ### Dependencies update
199
-
200
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
201
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
202
-
203
- ## 5.0.0 (2024-11-02)
204
-
205
- ### ⚠ BREAKING CHANGES
206
-
207
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
208
-
209
- ### Features
210
-
211
- * **async-queue:** A simple async queue like mutex and semaphore methodology for javascript and typescript. ([e753ff2](https://github.com/Alwatr/nanolib/commit/e753ff29cf53e0e6bcdd9661666ee60300960db3)) by @
212
- * **async-queue:** add isRunning ([2e54a0a](https://github.com/Alwatr/nanolib/commit/2e54a0a5200ccbfcc64e443728eb6d16513b4296)) by @
213
- * **async-queue:** Add waitForAllFinish method to AsyncQueue class ([3fdef04](https://github.com/Alwatr/nanolib/commit/3fdef04244c515b727c9ccabfd21d7667b561a83)) by @
214
- * **async-queue:** use `package-tracer` ([f570030](https://github.com/Alwatr/nanolib/commit/f570030140c97164b3a9184de739c59dd805055b)) by @
215
- * **AsyncQueue:** generic type for push method ([aec6710](https://github.com/Alwatr/nanolib/commit/aec6710041347452fa52bb2556e59d24bb0932a3)) by @
216
- * **AsyncQueue:** waitForFinish ([47decb4](https://github.com/Alwatr/nanolib/commit/47decb44a21338393d0820e9a965bf27f22dfbcd)) by @
217
-
218
- ### Bug Fixes
219
-
220
- * **async-queue:** remove wait deps ([83b2e11](https://github.com/Alwatr/nanolib/commit/83b2e115a939b90049c4af8d1cd6c4ebee282bf8)) by @
221
-
222
- ### Code Refactoring
223
-
224
- * prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
225
- * update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @
226
- * use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
227
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
228
- * **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @
229
-
230
- ### Miscellaneous Chores
231
-
232
- * **async-queue:** change the license to AGPL-3.0 ([e253149](https://github.com/Alwatr/nanolib/commit/e253149c3d1d51522406aa44db02a038aaf0d920)) by @
233
- * **deps-dev:** bump the development-dependencies group with 3 updates ([0e0ec0f](https://github.com/Alwatr/nanolib/commit/0e0ec0f7c66c849727563cabe0e88606aee49035)) by @
234
- * **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @
235
- * **deps:** update ([8e70dff](https://github.com/Alwatr/nanolib/commit/8e70dffb1e751496ef2e72d6cffd685f1fea44e3)) by @
236
- * **deps:** update ([f0b60d2](https://github.com/Alwatr/nanolib/commit/f0b60d24c9fae6190940baf95167a1175360d4b3)) by @
237
- * fix all typescript reference ([dea4c44](https://github.com/Alwatr/nanolib/commit/dea4c4414167602ea2f13888c6ecee24eb65ed93)) by @
238
- * include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
239
- * rename logger env ([38443ad](https://github.com/Alwatr/nanolib/commit/38443ade4677e857b5ebd4be417f5f2eb1818c87)) by @
240
- * Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
241
- * Update debug command in package.json ([be8403d](https://github.com/Alwatr/nanolib/commit/be8403dec754f2117259bb915b110ea386596401)) by @
242
- * Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
243
-
244
- ### Dependencies update
245
-
246
- * bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @
247
- * bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
248
- * bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
249
- * bump the development-dependencies group with 2 updates ([be5d6c2](https://github.com/Alwatr/nanolib/commit/be5d6c2d86b937f32cebc6848aaff85af07055dd)) by @
250
- * upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
251
- * update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @
252
- * update all ([53342f6](https://github.com/Alwatr/nanolib/commit/53342f67a8a013127f073540bc11929f1813c05c)) by @
253
- * update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
254
- * update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
255
- * upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @
256
-
257
- ## [1.3.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.7...@alwatr/async-queue@1.3.8) (2024-11-02)
258
-
259
- **Note:** Version bump only for package @alwatr/async-queue
260
-
261
- ## [1.3.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.6...@alwatr/async-queue@1.3.7) (2024-10-25)
262
-
263
- **Note:** Version bump only for package @alwatr/async-queue
264
-
265
- ## [1.3.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.5...@alwatr/async-queue@1.3.6) (2024-10-12)
266
-
267
- **Note:** Version bump only for package @alwatr/async-queue
268
-
269
- ## [1.3.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.4...@alwatr/async-queue@1.3.5) (2024-10-11)
270
-
271
- ### Code Refactoring
272
-
273
- - prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
274
-
275
- ## [1.3.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.3...@alwatr/async-queue@1.3.4) (2024-10-11)
276
-
277
- ### Miscellaneous Chores
278
-
279
- - include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
280
-
281
- ## [1.3.3](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.2...@alwatr/async-queue@1.3.3) (2024-10-11)
282
-
283
- **Note:** Version bump only for package @alwatr/async-queue
284
-
285
- ## [1.3.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.1...@alwatr/async-queue@1.3.2) (2024-10-10)
286
-
287
- ### Dependencies update
288
-
289
- - bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
290
-
291
- ## [1.3.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.0...@alwatr/async-queue@1.3.1) (2024-10-08)
292
-
293
- **Note:** Version bump only for package @alwatr/async-queue
294
-
295
- ## [1.3.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.11...@alwatr/async-queue@1.3.0) (2024-09-29)
296
-
297
- ### Features
298
-
299
- - **async-queue:** use `package-tracer` ([f570030](https://github.com/Alwatr/nanolib/commit/f570030140c97164b3a9184de739c59dd805055b)) by @mohammadhonarvar
300
-
301
- ### Code Refactoring
302
-
303
- - update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @alimd
304
- - use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
305
- - **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @alimd
306
-
307
- ### Miscellaneous Chores
308
-
309
- - **async-queue:** change the license to AGPL-3.0 ([e253149](https://github.com/Alwatr/nanolib/commit/e253149c3d1d51522406aa44db02a038aaf0d920)) by @ArmanAsadian
310
- - Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
311
-
312
- ### Dependencies update
313
-
314
- - bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @dependabot[bot]
315
-
316
- ## [1.2.11](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.10...@alwatr/async-queue@1.2.11) (2024-09-21)
317
-
318
- **Note:** Version bump only for package @alwatr/async-queue
319
-
320
- ## [1.2.10](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.9...@alwatr/async-queue@1.2.10) (2024-09-15)
321
-
322
- ### Dependencies update
323
-
324
- - bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
325
- - update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @alimd
326
-
327
- ## [1.2.9](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.8...@alwatr/async-queue@1.2.9) (2024-08-31)
328
-
329
- ### Miscellaneous Chores
330
-
331
- - Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
332
-
333
- ## [1.2.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.7...@alwatr/async-queue@1.2.8) (2024-08-31)
334
-
335
- ### Dependencies update
336
-
337
- - update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
338
-
339
- ## [1.2.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.6...@alwatr/async-queue@1.2.7) (2024-07-04)
340
-
341
- ### Dependencies update
342
-
343
- - update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
344
-
345
- ## [1.2.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.5...@alwatr/async-queue@1.2.6) (2024-05-12)
346
-
347
- ### Dependencies update
348
-
349
- - upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @alimd
350
-
351
- ## [1.2.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.4...@alwatr/async-queue@1.2.5) (2024-04-25)
352
-
353
- **Note:** Version bump only for package @alwatr/async-queue
354
-
355
- ## [1.2.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.3...@alwatr/async-queue@1.2.4) (2024-03-28)
356
-
357
- **Note:** Version bump only for package @alwatr/async-queue
358
-
359
- ## [1.2.3](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.2...@alwatr/async-queue@1.2.3) (2024-01-31)
360
-
361
- ### Miscellaneous Chores
362
-
363
- - **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @alimd
364
-
365
- ## [1.2.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.1...@alwatr/async-queue@1.2.2) (2024-01-24)
366
-
367
- **Note:** Version bump only for package @alwatr/async-queue
368
-
369
- ## [1.2.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.0...@alwatr/async-queue@1.2.1) (2024-01-20)
370
-
371
- **Note:** Version bump only for package @alwatr/async-queue
372
-
373
- ## [1.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.1.1...@alwatr/async-queue@1.2.0) (2024-01-16)
374
-
375
- ### Features
376
-
377
- - **async-queue:** Add waitForAllFinish method to AsyncQueue class ([3fdef04](https://github.com/Alwatr/nanolib/commit/3fdef04244c515b727c9ccabfd21d7667b561a83)) by @alimd
378
-
379
- ## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.1.0...@alwatr/async-queue@1.1.1) (2024-01-16)
380
-
381
- **Note:** Version bump only for package @alwatr/async-queue
382
-
383
- # [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.2...@alwatr/async-queue@1.1.0) (2024-01-08)
384
-
385
- ### Features
386
-
387
- - **AsyncQueue:** generic type for push method ([aec6710](https://github.com/Alwatr/nanolib/commit/aec6710041347452fa52bb2556e59d24bb0932a3)) by @alimd
388
- - **AsyncQueue:** waitForFinish ([47decb4](https://github.com/Alwatr/nanolib/commit/47decb44a21338393d0820e9a965bf27f22dfbcd)) by @alimd
389
-
390
- ## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.1...@alwatr/async-queue@1.0.2) (2024-01-08)
391
-
392
- **Note:** Version bump only for package @alwatr/async-queue
393
-
394
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.0...@alwatr/async-queue@1.0.1) (2024-01-03)
395
-
396
- **Note:** Version bump only for package @alwatr/async-queue
397
-
398
- # 1.0.0 (2024-01-03)
399
-
400
- ### Bug Fixes
401
-
402
- - **async-queue:** remove wait deps ([83b2e11](https://github.com/Alwatr/nanolib/commit/83b2e115a939b90049c4af8d1cd6c4ebee282bf8)) by @njfamirm
403
-
404
- ### Features
405
-
406
- - **async-queue:** A simple async queue like mutex and semaphore methodology for javascript and typescript. ([e753ff2](https://github.com/Alwatr/nanolib/commit/e753ff29cf53e0e6bcdd9661666ee60300960db3)) by @alimd
407
- - **async-queue:** add isRunning ([2e54a0a](https://github.com/Alwatr/nanolib/commit/2e54a0a5200ccbfcc64e443728eb6d16513b4296)) by @njfamirm
package/dist/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/async-queue v5.5.29 */
2
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{AsyncQueue:()=>AsyncQueue});module.exports=__toCommonJS(main_exports);var import_flatomise=require("@alwatr/flatomise");var AsyncQueue=class{constructor(){this.queue__={}}async push(taskId,task){const flatomise=(0,import_flatomise.newFlatomise)();const previousTaskPromise=this.queue__[taskId];this.queue__[taskId]=flatomise.promise;try{await previousTaskPromise}catch(_e){}setTimeout(()=>{task().then(flatomise.resolve,flatomise.reject).then(()=>{if(this.queue__[taskId]===flatomise.promise){delete this.queue__[taskId]}})},0);return flatomise.promise}isRunning(taskId){return this.queue__[taskId]!==void 0}waitForFinish(taskId){return this.queue__[taskId]??Promise.resolve()}waitForAllFinish(){return Promise.all(Object.values(this.queue__))}};0&&(module.exports={AsyncQueue});
3
- //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {newFlatomise} from '@alwatr/flatomise';\n\nimport type {} from '@alwatr/type-helper';\n\n/**\n * A queue that executes async tasks in order like mutex and semaphore methodology\n *\n * @example\n * ```ts\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * }\n * ```\n */\nexport class AsyncQueue {\n /**\n * A record of task IDs and their corresponding last queued task promises.\n */\n private queue__: DictionaryOpt<Promise<unknown>> = {};\n\n /**\n * Push a async task to the queue.\n *\n * @param taskId task id\n * @param task async task\n * @returns A promise that resolves when the task is done.\n *\n * @example\n * ```typescript\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * ```\n */\n public async push<T>(taskId: string, task: () => Promise<T>): Promise<T> {\n const flatomise = newFlatomise<T>();\n\n const previousTaskPromise = this.queue__[taskId];\n this.queue__[taskId] = flatomise.promise;\n\n try {\n await previousTaskPromise;\n }\n catch (_e) {\n // ignore\n }\n\n setTimeout(() => {\n task()\n .then(flatomise.resolve, flatomise.reject)\n .then(() => {\n if (this.queue__[taskId] === flatomise.promise) {\n delete this.queue__[taskId];\n }\n });\n }, 0);\n\n return flatomise.promise;\n }\n\n /**\n * Check if the task running in the queue.\n *\n * @param taskId task id\n * @returns true if the task is running, otherwise false.\n * @example\n * ```typescript\n * if (queue.isRunning('longTaskId')) {\n * // ...\n * }\n * ```\n */\n public isRunning(taskId: string): boolean {\n return this.queue__[taskId] !== undefined;\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n *\n * @param taskId task id\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForFinish('longTaskId');\n * ```\n */\n public waitForFinish(taskId: string): Promise<unknown> {\n return this.queue__[taskId] ?? Promise.resolve();\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForAllFinish();\n * ```\n */\n public waitForAllFinish(): Promise<unknown[]> {\n return Promise.all(Object.values(this.queue__));\n }\n}\n"],
5
- "mappings": ";qqBAAA,sIAA2B,6BAkBpB,IAAM,WAAN,KAAiB,CAAjB,cAIL,KAAQ,QAA2C,CAAC,EAmBpD,MAAa,KAAQ,OAAgB,KAAoC,CACvE,MAAM,aAAY,+BAAgB,EAElC,MAAM,oBAAsB,KAAK,QAAQ,MAAM,EAC/C,KAAK,QAAQ,MAAM,EAAI,UAAU,QAEjC,GAAI,CACF,MAAM,mBACR,OACO,GAAI,CAEX,CAEA,WAAW,IAAM,CACf,KAAK,EACF,KAAK,UAAU,QAAS,UAAU,MAAM,EACxC,KAAK,IAAM,CACV,GAAI,KAAK,QAAQ,MAAM,IAAM,UAAU,QAAS,CAC9C,OAAO,KAAK,QAAQ,MAAM,CAC5B,CACF,CAAC,CACL,EAAG,CAAC,EAEJ,OAAO,UAAU,OACnB,CAcO,UAAU,OAAyB,CACxC,OAAO,KAAK,QAAQ,MAAM,IAAM,MAClC,CAYO,cAAc,OAAkC,CACrD,OAAO,KAAK,QAAQ,MAAM,GAAK,QAAQ,QAAQ,CACjD,CAUO,kBAAuC,CAC5C,OAAO,QAAQ,IAAI,OAAO,OAAO,KAAK,OAAO,CAAC,CAChD,CACF",
6
- "names": []
7
- }
package/dist/main.mjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/async-queue v5.5.29 */
2
- import{newFlatomise}from"@alwatr/flatomise";var AsyncQueue=class{constructor(){this.queue__={}}async push(taskId,task){const flatomise=newFlatomise();const previousTaskPromise=this.queue__[taskId];this.queue__[taskId]=flatomise.promise;try{await previousTaskPromise}catch(_e){}setTimeout(()=>{task().then(flatomise.resolve,flatomise.reject).then(()=>{if(this.queue__[taskId]===flatomise.promise){delete this.queue__[taskId]}})},0);return flatomise.promise}isRunning(taskId){return this.queue__[taskId]!==void 0}waitForFinish(taskId){return this.queue__[taskId]??Promise.resolve()}waitForAllFinish(){return Promise.all(Object.values(this.queue__))}};export{AsyncQueue};
3
- //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {newFlatomise} from '@alwatr/flatomise';\n\nimport type {} from '@alwatr/type-helper';\n\n/**\n * A queue that executes async tasks in order like mutex and semaphore methodology\n *\n * @example\n * ```ts\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * }\n * ```\n */\nexport class AsyncQueue {\n /**\n * A record of task IDs and their corresponding last queued task promises.\n */\n private queue__: DictionaryOpt<Promise<unknown>> = {};\n\n /**\n * Push a async task to the queue.\n *\n * @param taskId task id\n * @param task async task\n * @returns A promise that resolves when the task is done.\n *\n * @example\n * ```typescript\n * const queue = new AsyncQueue();\n *\n * function longTask() {\n * queue.push('longTaskId', async () => {\n * // ...\n * });\n * ```\n */\n public async push<T>(taskId: string, task: () => Promise<T>): Promise<T> {\n const flatomise = newFlatomise<T>();\n\n const previousTaskPromise = this.queue__[taskId];\n this.queue__[taskId] = flatomise.promise;\n\n try {\n await previousTaskPromise;\n }\n catch (_e) {\n // ignore\n }\n\n setTimeout(() => {\n task()\n .then(flatomise.resolve, flatomise.reject)\n .then(() => {\n if (this.queue__[taskId] === flatomise.promise) {\n delete this.queue__[taskId];\n }\n });\n }, 0);\n\n return flatomise.promise;\n }\n\n /**\n * Check if the task running in the queue.\n *\n * @param taskId task id\n * @returns true if the task is running, otherwise false.\n * @example\n * ```typescript\n * if (queue.isRunning('longTaskId')) {\n * // ...\n * }\n * ```\n */\n public isRunning(taskId: string): boolean {\n return this.queue__[taskId] !== undefined;\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n *\n * @param taskId task id\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForFinish('longTaskId');\n * ```\n */\n public waitForFinish(taskId: string): Promise<unknown> {\n return this.queue__[taskId] ?? Promise.resolve();\n }\n\n /**\n * Wait for the all tasks in the queue to finish.\n * @returns A promise that resolves when all tasks are done.\n * @example\n * ```typescript\n * await queue.waitForAllFinish();\n * ```\n */\n public waitForAllFinish(): Promise<unknown[]> {\n return Promise.all(Object.values(this.queue__));\n }\n}\n"],
5
- "mappings": ";AAAA,OAAQ,iBAAmB,oBAkBpB,IAAM,WAAN,KAAiB,CAAjB,cAIL,KAAQ,QAA2C,CAAC,EAmBpD,MAAa,KAAQ,OAAgB,KAAoC,CACvE,MAAM,UAAY,aAAgB,EAElC,MAAM,oBAAsB,KAAK,QAAQ,MAAM,EAC/C,KAAK,QAAQ,MAAM,EAAI,UAAU,QAEjC,GAAI,CACF,MAAM,mBACR,OACO,GAAI,CAEX,CAEA,WAAW,IAAM,CACf,KAAK,EACF,KAAK,UAAU,QAAS,UAAU,MAAM,EACxC,KAAK,IAAM,CACV,GAAI,KAAK,QAAQ,MAAM,IAAM,UAAU,QAAS,CAC9C,OAAO,KAAK,QAAQ,MAAM,CAC5B,CACF,CAAC,CACL,EAAG,CAAC,EAEJ,OAAO,UAAU,OACnB,CAcO,UAAU,OAAyB,CACxC,OAAO,KAAK,QAAQ,MAAM,IAAM,MAClC,CAYO,cAAc,OAAkC,CACrD,OAAO,KAAK,QAAQ,MAAM,GAAK,QAAQ,QAAQ,CACjD,CAUO,kBAAuC,CAC5C,OAAO,QAAQ,IAAI,OAAO,OAAO,KAAK,OAAO,CAAC,CAChD,CACF",
6
- "names": []
7
- }