@alwatr/async-queue 5.5.30 → 6.0.1

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.1 */
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=8B362BD8DFC1810E64756E2164756E21
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": "8B362BD8DFC1810E64756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,33 +1,59 @@
1
1
  {
2
2
  "name": "@alwatr/async-queue",
3
+ "version": "6.0.1",
3
4
  "description": "A queue that executes async tasks in order like mutex and semaphore methodology for javascript and typescript.",
4
- "version": "5.5.30",
5
+ "license": "MPL-2.0",
5
6
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
7
+ "type": "module",
8
+ "repository": {
9
+ "directory": "packages/async-queue",
10
+ "type": "git",
11
+ "url": "https://github.com/Alwatr/nanolib"
12
+ },
13
+ "homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/async-queue#readme",
6
14
  "bugs": "https://github.com/Alwatr/nanolib/issues",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/main.d.ts",
18
+ "default": "./dist/main.js"
19
+ }
20
+ },
7
21
  "dependencies": {
8
- "@alwatr/flatomise": "5.5.29"
22
+ "@alwatr/flatomise": "6.0.1"
9
23
  },
10
24
  "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",
25
+ "@alwatr/nano-build": "7.0.1",
26
+ "@alwatr/prettier-config": "7.0.1",
27
+ "@alwatr/tsconfig-base": "8.0.0",
28
+ "@alwatr/type-helper": "8.0.1",
15
29
  "typescript": "^5.9.3"
16
30
  },
17
- "exports": {
18
- ".": {
19
- "types": "./dist/main.d.ts",
20
- "import": "./dist/main.mjs",
21
- "require": "./dist/main.cjs"
22
- }
31
+ "scripts": {
32
+ "b": "bun run build",
33
+ "build": "bun run build:ts && bun run build:es",
34
+ "build:es": "nano-build --preset=module src/main.ts",
35
+ "build:ts": "tsc --build",
36
+ "c": "bun run clean",
37
+ "cb": "bun run clean && bun run build",
38
+ "clean": "rm -rfv dist *.tsbuildinfo",
39
+ "d": "bun run build:es && bun",
40
+ "t": "bun run test",
41
+ "test": "bun test",
42
+ "w": "bun run watch",
43
+ "watch": "bun run watch:ts & bun run watch:es",
44
+ "watch:es": "bun run build:es --watch",
45
+ "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
23
46
  },
24
47
  "files": [
25
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
48
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
49
+ "README.md",
26
50
  "LICENSE",
27
51
  "!demo/**/*",
28
52
  "!**/*.test.js"
29
53
  ],
30
- "homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/async-queue#readme",
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
31
57
  "keywords": [
32
58
  "alwatr",
33
59
  "async",
@@ -53,35 +79,6 @@
53
79
  "utility",
54
80
  "utils"
55
81
  ],
56
- "license": "MPL-2.0",
57
- "main": "./dist/main.cjs",
58
- "module": "./dist/main.mjs",
59
82
  "prettier": "@alwatr/prettier-config",
60
- "publishConfig": {
61
- "access": "public"
62
- },
63
- "repository": {
64
- "type": "git",
65
- "url": "https://github.com/Alwatr/nanolib",
66
- "directory": "packages/async-queue"
67
- },
68
- "scripts": {
69
- "b": "bun run build",
70
- "build": "bun run build:ts && bun run build:es",
71
- "build:es": "nano-build --preset=module",
72
- "build:ts": "tsc --build",
73
- "c": "bun run clean",
74
- "cb": "bun run clean && bun run build",
75
- "clean": "rm -rfv dist *.tsbuildinfo",
76
- "d": "bun run build:es && bun --enable-source-maps --trace-warnings",
77
- "t": "bun run test",
78
- "test": "bun test",
79
- "w": "bun run watch",
80
- "watch": "bun run watch:ts & bun run watch:es",
81
- "watch:es": "bun run build:es --watch",
82
- "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
83
- },
84
- "type": "module",
85
- "types": "./dist/main.d.ts",
86
- "gitHead": "def1decf8f496f4b0d3d3ab952c346c689c30160"
83
+ "gitHead": "f843742e94d6ebed3921d57b624d9deb35c2c102"
87
84
  }
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,411 +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.30](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.29...@alwatr/async-queue@5.5.30) (2026-03-18)
7
-
8
- **Note:** Version bump only for package @alwatr/async-queue
9
-
10
- ## [5.5.29](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.28...@alwatr/async-queue@5.5.29) (2026-03-16)
11
-
12
- ### 🔨 Code Refactoring
13
-
14
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
15
-
16
- ## [5.5.28](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.27...@alwatr/async-queue@5.5.28) (2026-02-18)
17
-
18
- **Note:** Version bump only for package @alwatr/async-queue
19
-
20
- ## [5.5.27](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.26...@alwatr/async-queue@5.5.27) (2025-12-23)
21
-
22
- **Note:** Version bump only for package @alwatr/async-queue
23
-
24
- ## [5.5.26](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.25...@alwatr/async-queue@5.5.26) (2025-12-13)
25
-
26
- **Note:** Version bump only for package @alwatr/async-queue
27
-
28
- ## [5.5.25](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.24...@alwatr/async-queue@5.5.25) (2025-12-10)
29
-
30
- **Note:** Version bump only for package @alwatr/async-queue
31
-
32
- ## [5.5.24](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.23...@alwatr/async-queue@5.5.24) (2025-11-18)
33
-
34
- ### 🐛 Bug Fixes
35
-
36
- * add type imports from @alwatr/nano-build and @alwatr/type-helper across multiple packages ([5ab7f15](https://github.com/Alwatr/nanolib/commit/5ab7f159ba57788bf8df40fa96a3027f589d5a77))
37
-
38
- ### 🔨 Code Refactoring
39
-
40
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
41
-
42
- ## [5.5.23](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.22...@alwatr/async-queue@5.5.23) (2025-11-15)
43
-
44
- **Note:** Version bump only for package @alwatr/async-queue
45
-
46
- ## [5.5.22](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.21...@alwatr/async-queue@5.5.22) (2025-11-15)
47
-
48
- **Note:** Version bump only for package @alwatr/async-queue
49
-
50
- ## [5.5.21](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.20...@alwatr/async-queue@5.5.21) (2025-11-04)
51
-
52
- **Note:** Version bump only for package @alwatr/async-queue
53
-
54
- ## [5.5.20](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.19...@alwatr/async-queue@5.5.20) (2025-10-06)
55
-
56
- ### 🔗 Dependencies update
57
-
58
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
59
-
60
- ## [5.5.19](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.18...@alwatr/async-queue@5.5.19) (2025-09-27)
61
-
62
- ### 🧹 Miscellaneous Chores
63
-
64
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
65
-
66
- ## [5.5.18](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.17...@alwatr/async-queue@5.5.18) (2025-09-22)
67
-
68
- **Note:** Version bump only for package @alwatr/async-queue
69
-
70
- ## [5.5.17](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.16...@alwatr/async-queue@5.5.17) (2025-09-22)
71
-
72
- **Note:** Version bump only for package @alwatr/async-queue
73
-
74
- ## [5.5.16](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.15...@alwatr/async-queue@5.5.16) (2025-09-21)
75
-
76
- **Note:** Version bump only for package @alwatr/async-queue
77
-
78
- ## [5.5.15](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.14...@alwatr/async-queue@5.5.15) (2025-09-20)
79
-
80
- **Note:** Version bump only for package @alwatr/async-queue
81
-
82
- ## [5.5.14](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.13...@alwatr/async-queue@5.5.14) (2025-09-19)
83
-
84
- **Note:** Version bump only for package @alwatr/async-queue
85
-
86
- ## [5.5.13](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.12...@alwatr/async-queue@5.5.13) (2025-09-15)
87
-
88
- **Note:** Version bump only for package @alwatr/async-queue
89
-
90
- ## [5.5.12](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.11...@alwatr/async-queue@5.5.12) (2025-09-13)
91
-
92
- **Note:** Version bump only for package @alwatr/async-queue
93
-
94
- ## [5.5.11](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.10...@alwatr/async-queue@5.5.11) (2025-09-13)
95
-
96
- ### 🧹 Miscellaneous Chores
97
-
98
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
99
-
100
- ## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.9...@alwatr/async-queue@5.5.10) (2025-09-09)
101
-
102
- ### 🧹 Miscellaneous Chores
103
-
104
- * remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
105
-
106
- ## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.8...@alwatr/async-queue@5.5.9) (2025-09-06)
107
-
108
- **Note:** Version bump only for package @alwatr/async-queue
109
-
110
- ## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.7...@alwatr/async-queue@5.5.8) (2025-09-05)
111
-
112
- ### 🔗 Dependencies update
113
-
114
- * update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
115
-
116
- ## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.6...@alwatr/async-queue@5.5.7) (2025-09-01)
117
-
118
- ### 🔗 Dependencies update
119
-
120
- * update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
121
-
122
- ## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.5...@alwatr/async-queue@5.5.6) (2025-08-23)
123
-
124
- **Note:** Version bump only for package @alwatr/async-queue
125
-
126
- ## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.3...@alwatr/async-queue@5.5.5) (2025-08-23)
127
-
128
- ### 🐛 Bug Fixes
129
-
130
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
131
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
132
-
133
- ### 🔨 Code Refactoring
134
-
135
- * 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))
136
-
137
- ### 🧹 Miscellaneous Chores
138
-
139
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
140
-
141
- ### 🔗 Dependencies update
142
-
143
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
144
-
145
- ## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.3...@alwatr/async-queue@5.5.4) (2025-08-23)
146
-
147
- ### Code Refactoring
148
-
149
- * 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
150
-
151
- ## <small>5.5.3 (2025-04-15)</small>
152
-
153
- **Note:** Version bump only for package @alwatr/async-queue
154
-
155
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.1...@alwatr/async-queue@5.5.2) (2025-04-01)
156
-
157
- **Note:** Version bump only for package @alwatr/async-queue
158
-
159
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.5.0...@alwatr/async-queue@5.5.1) (2025-03-18)
160
-
161
- **Note:** Version bump only for package @alwatr/async-queue
162
-
163
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@5.4.0...@alwatr/async-queue@5.5.0) (2025-03-06)
164
-
165
- ### Miscellaneous Chores
166
-
167
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
168
-
169
- ### Dependencies update
170
-
171
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
172
-
173
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.8...@alwatr/async-queue@5.4.0) (2025-02-18)
174
-
175
- ## 5.3.0 (2025-02-03)
176
-
177
- ### Miscellaneous Chores
178
-
179
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
180
-
181
- ### Dependencies update
182
-
183
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
184
- * 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 @
185
-
186
- ## 5.0.0 (2024-11-02)
187
-
188
- ### ⚠ BREAKING CHANGES
189
-
190
- * 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.
191
-
192
- ### Code Refactoring
193
-
194
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
195
-
196
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
197
-
198
- ### Miscellaneous Chores
199
-
200
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
201
-
202
- ### Dependencies update
203
-
204
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
205
- * 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
206
-
207
- ## 5.0.0 (2024-11-02)
208
-
209
- ### ⚠ BREAKING CHANGES
210
-
211
- * 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.
212
-
213
- ### Features
214
-
215
- * **async-queue:** A simple async queue like mutex and semaphore methodology for javascript and typescript. ([e753ff2](https://github.com/Alwatr/nanolib/commit/e753ff29cf53e0e6bcdd9661666ee60300960db3)) by @
216
- * **async-queue:** add isRunning ([2e54a0a](https://github.com/Alwatr/nanolib/commit/2e54a0a5200ccbfcc64e443728eb6d16513b4296)) by @
217
- * **async-queue:** Add waitForAllFinish method to AsyncQueue class ([3fdef04](https://github.com/Alwatr/nanolib/commit/3fdef04244c515b727c9ccabfd21d7667b561a83)) by @
218
- * **async-queue:** use `package-tracer` ([f570030](https://github.com/Alwatr/nanolib/commit/f570030140c97164b3a9184de739c59dd805055b)) by @
219
- * **AsyncQueue:** generic type for push method ([aec6710](https://github.com/Alwatr/nanolib/commit/aec6710041347452fa52bb2556e59d24bb0932a3)) by @
220
- * **AsyncQueue:** waitForFinish ([47decb4](https://github.com/Alwatr/nanolib/commit/47decb44a21338393d0820e9a965bf27f22dfbcd)) by @
221
-
222
- ### Bug Fixes
223
-
224
- * **async-queue:** remove wait deps ([83b2e11](https://github.com/Alwatr/nanolib/commit/83b2e115a939b90049c4af8d1cd6c4ebee282bf8)) by @
225
-
226
- ### Code Refactoring
227
-
228
- * prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
229
- * update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @
230
- * use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
231
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
232
- * **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @
233
-
234
- ### Miscellaneous Chores
235
-
236
- * **async-queue:** change the license to AGPL-3.0 ([e253149](https://github.com/Alwatr/nanolib/commit/e253149c3d1d51522406aa44db02a038aaf0d920)) by @
237
- * **deps-dev:** bump the development-dependencies group with 3 updates ([0e0ec0f](https://github.com/Alwatr/nanolib/commit/0e0ec0f7c66c849727563cabe0e88606aee49035)) by @
238
- * **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @
239
- * **deps:** update ([8e70dff](https://github.com/Alwatr/nanolib/commit/8e70dffb1e751496ef2e72d6cffd685f1fea44e3)) by @
240
- * **deps:** update ([f0b60d2](https://github.com/Alwatr/nanolib/commit/f0b60d24c9fae6190940baf95167a1175360d4b3)) by @
241
- * fix all typescript reference ([dea4c44](https://github.com/Alwatr/nanolib/commit/dea4c4414167602ea2f13888c6ecee24eb65ed93)) by @
242
- * include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
243
- * rename logger env ([38443ad](https://github.com/Alwatr/nanolib/commit/38443ade4677e857b5ebd4be417f5f2eb1818c87)) by @
244
- * Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
245
- * Update debug command in package.json ([be8403d](https://github.com/Alwatr/nanolib/commit/be8403dec754f2117259bb915b110ea386596401)) by @
246
- * Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
247
-
248
- ### Dependencies update
249
-
250
- * bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @
251
- * bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
252
- * bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
253
- * bump the development-dependencies group with 2 updates ([be5d6c2](https://github.com/Alwatr/nanolib/commit/be5d6c2d86b937f32cebc6848aaff85af07055dd)) by @
254
- * upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
255
- * update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @
256
- * update all ([53342f6](https://github.com/Alwatr/nanolib/commit/53342f67a8a013127f073540bc11929f1813c05c)) by @
257
- * update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
258
- * update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
259
- * upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @
260
-
261
- ## [1.3.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.7...@alwatr/async-queue@1.3.8) (2024-11-02)
262
-
263
- **Note:** Version bump only for package @alwatr/async-queue
264
-
265
- ## [1.3.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.6...@alwatr/async-queue@1.3.7) (2024-10-25)
266
-
267
- **Note:** Version bump only for package @alwatr/async-queue
268
-
269
- ## [1.3.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.5...@alwatr/async-queue@1.3.6) (2024-10-12)
270
-
271
- **Note:** Version bump only for package @alwatr/async-queue
272
-
273
- ## [1.3.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.4...@alwatr/async-queue@1.3.5) (2024-10-11)
274
-
275
- ### Code Refactoring
276
-
277
- - prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
278
-
279
- ## [1.3.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.3...@alwatr/async-queue@1.3.4) (2024-10-11)
280
-
281
- ### Miscellaneous Chores
282
-
283
- - include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
284
-
285
- ## [1.3.3](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.2...@alwatr/async-queue@1.3.3) (2024-10-11)
286
-
287
- **Note:** Version bump only for package @alwatr/async-queue
288
-
289
- ## [1.3.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.1...@alwatr/async-queue@1.3.2) (2024-10-10)
290
-
291
- ### Dependencies update
292
-
293
- - bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
294
-
295
- ## [1.3.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.3.0...@alwatr/async-queue@1.3.1) (2024-10-08)
296
-
297
- **Note:** Version bump only for package @alwatr/async-queue
298
-
299
- ## [1.3.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.11...@alwatr/async-queue@1.3.0) (2024-09-29)
300
-
301
- ### Features
302
-
303
- - **async-queue:** use `package-tracer` ([f570030](https://github.com/Alwatr/nanolib/commit/f570030140c97164b3a9184de739c59dd805055b)) by @mohammadhonarvar
304
-
305
- ### Code Refactoring
306
-
307
- - update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @alimd
308
- - use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
309
- - **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @alimd
310
-
311
- ### Miscellaneous Chores
312
-
313
- - **async-queue:** change the license to AGPL-3.0 ([e253149](https://github.com/Alwatr/nanolib/commit/e253149c3d1d51522406aa44db02a038aaf0d920)) by @ArmanAsadian
314
- - Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
315
-
316
- ### Dependencies update
317
-
318
- - bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @dependabot[bot]
319
-
320
- ## [1.2.11](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.10...@alwatr/async-queue@1.2.11) (2024-09-21)
321
-
322
- **Note:** Version bump only for package @alwatr/async-queue
323
-
324
- ## [1.2.10](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.9...@alwatr/async-queue@1.2.10) (2024-09-15)
325
-
326
- ### Dependencies update
327
-
328
- - bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
329
- - update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @alimd
330
-
331
- ## [1.2.9](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.8...@alwatr/async-queue@1.2.9) (2024-08-31)
332
-
333
- ### Miscellaneous Chores
334
-
335
- - Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
336
-
337
- ## [1.2.8](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.7...@alwatr/async-queue@1.2.8) (2024-08-31)
338
-
339
- ### Dependencies update
340
-
341
- - update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
342
-
343
- ## [1.2.7](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.6...@alwatr/async-queue@1.2.7) (2024-07-04)
344
-
345
- ### Dependencies update
346
-
347
- - update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
348
-
349
- ## [1.2.6](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.5...@alwatr/async-queue@1.2.6) (2024-05-12)
350
-
351
- ### Dependencies update
352
-
353
- - upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @alimd
354
-
355
- ## [1.2.5](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.4...@alwatr/async-queue@1.2.5) (2024-04-25)
356
-
357
- **Note:** Version bump only for package @alwatr/async-queue
358
-
359
- ## [1.2.4](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.3...@alwatr/async-queue@1.2.4) (2024-03-28)
360
-
361
- **Note:** Version bump only for package @alwatr/async-queue
362
-
363
- ## [1.2.3](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.2...@alwatr/async-queue@1.2.3) (2024-01-31)
364
-
365
- ### Miscellaneous Chores
366
-
367
- - **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @alimd
368
-
369
- ## [1.2.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.1...@alwatr/async-queue@1.2.2) (2024-01-24)
370
-
371
- **Note:** Version bump only for package @alwatr/async-queue
372
-
373
- ## [1.2.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.2.0...@alwatr/async-queue@1.2.1) (2024-01-20)
374
-
375
- **Note:** Version bump only for package @alwatr/async-queue
376
-
377
- ## [1.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.1.1...@alwatr/async-queue@1.2.0) (2024-01-16)
378
-
379
- ### Features
380
-
381
- - **async-queue:** Add waitForAllFinish method to AsyncQueue class ([3fdef04](https://github.com/Alwatr/nanolib/commit/3fdef04244c515b727c9ccabfd21d7667b561a83)) by @alimd
382
-
383
- ## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.1.0...@alwatr/async-queue@1.1.1) (2024-01-16)
384
-
385
- **Note:** Version bump only for package @alwatr/async-queue
386
-
387
- # [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.2...@alwatr/async-queue@1.1.0) (2024-01-08)
388
-
389
- ### Features
390
-
391
- - **AsyncQueue:** generic type for push method ([aec6710](https://github.com/Alwatr/nanolib/commit/aec6710041347452fa52bb2556e59d24bb0932a3)) by @alimd
392
- - **AsyncQueue:** waitForFinish ([47decb4](https://github.com/Alwatr/nanolib/commit/47decb44a21338393d0820e9a965bf27f22dfbcd)) by @alimd
393
-
394
- ## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.1...@alwatr/async-queue@1.0.2) (2024-01-08)
395
-
396
- **Note:** Version bump only for package @alwatr/async-queue
397
-
398
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/async-queue@1.0.0...@alwatr/async-queue@1.0.1) (2024-01-03)
399
-
400
- **Note:** Version bump only for package @alwatr/async-queue
401
-
402
- # 1.0.0 (2024-01-03)
403
-
404
- ### Bug Fixes
405
-
406
- - **async-queue:** remove wait deps ([83b2e11](https://github.com/Alwatr/nanolib/commit/83b2e115a939b90049c4af8d1cd6c4ebee282bf8)) by @njfamirm
407
-
408
- ### Features
409
-
410
- - **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
411
- - **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.30 */
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.30 */
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
- }