@alwatr/async-queue 9.1.0 → 9.1.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 +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +7 -7
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 📦 @alwatr/async-queue v9.1.
|
|
1
|
+
/* 📦 @alwatr/async-queue v9.1.1 */
|
|
2
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
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=4C6DFF568EBB98B964756E2164756E21
|
|
5
5
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"import {newFlatomise} from '@alwatr/flatomise';\n\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
6
|
],
|
|
7
7
|
"mappings": ";AAAA,uBAAQ,0BAiBD,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": "
|
|
8
|
+
"debugId": "4C6DFF568EBB98B964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/async-queue",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.1",
|
|
4
4
|
"description": "A queue that executes async tasks in order like mutex and semaphore methodology for javascript and typescript.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "https://github.com/Alwatr/alwatr",
|
|
11
11
|
"directory": "pkg/nanolib/async-queue"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://github.com/Alwatr/alwatr/tree/
|
|
13
|
+
"homepage": "https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/async-queue#readme",
|
|
14
14
|
"bugs": "https://github.com/Alwatr/alwatr/issues",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@alwatr/flatomise": "9.1.
|
|
23
|
+
"@alwatr/flatomise": "9.1.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@alwatr/nano-build": "9.1.
|
|
27
|
-
"@alwatr/tsconfig-base": "9.1.
|
|
28
|
-
"@alwatr/type-helper": "9.1.
|
|
26
|
+
"@alwatr/nano-build": "9.1.1",
|
|
27
|
+
"@alwatr/tsconfig-base": "9.1.1",
|
|
28
|
+
"@alwatr/type-helper": "9.1.1",
|
|
29
29
|
"typescript": "^6.0.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"utility",
|
|
80
80
|
"utils"
|
|
81
81
|
],
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "38fb79dd8b6cf48108ae6492ecd7a285c7633e9b"
|
|
83
83
|
}
|