@alwatr/async-queue 6.0.2 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IACrB;;OAEG;IACH,OAAO,CAAC,OAAO,CAAuC;IAEtD;;;;;;;;;;;;;;;;OAgBG;IACU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA0BxE;;;;;;;;;;;OAWG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIzC;;;;;;;;;OASG;IACI,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD;;;;;;;OAOG;IACI,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG9C"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAU;IACrB;;OAEG;IACH,OAAO,CAAC,OAAO,CAAuC;IAEtD;;;;;;;;;;;;;;;;OAgBG;IACU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA0BxE;;;;;;;;;;;OAWG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIzC;;;;;;;;;OASG;IACI,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD;;;;;;;OAOG;IACI,gBAAgB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG9C"}
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- /* 📦 @alwatr/async-queue v6.0.2 */
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=B06207B7B27AE96764756E2164756E21
4
+ //# debugId=4C6DFF568EBB98B964756E2164756E21
5
5
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts"],
4
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"
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
- "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": "B06207B7B27AE96764756E2164756E21",
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": "4C6DFF568EBB98B964756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "@alwatr/async-queue",
3
- "version": "6.0.2",
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
- "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
+ "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
7
7
  "type": "module",
8
8
  "repository": {
9
- "directory": "packages/async-queue",
10
9
  "type": "git",
11
- "url": "https://github.com/Alwatr/nanolib"
10
+ "url": "https://github.com/Alwatr/alwatr",
11
+ "directory": "pkg/nanolib/async-queue"
12
12
  },
13
- "homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/async-queue#readme",
14
- "bugs": "https://github.com/Alwatr/nanolib/issues",
13
+ "homepage": "https://github.com/Alwatr/alwatr/tree/next/pkg/nanolib/async-queue#readme",
14
+ "bugs": "https://github.com/Alwatr/alwatr/issues",
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/main.d.ts",
18
+ "import": "./dist/main.js",
18
19
  "default": "./dist/main.js"
19
20
  }
20
21
  },
21
22
  "dependencies": {
22
- "@alwatr/flatomise": "6.0.2"
23
+ "@alwatr/flatomise": "9.1.1"
23
24
  },
24
25
  "devDependencies": {
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.2",
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": {
@@ -33,23 +33,23 @@
33
33
  "build": "bun run build:ts && bun run build:es",
34
34
  "build:es": "nano-build --preset=module src/main.ts",
35
35
  "build:ts": "tsc --build",
36
- "c": "bun run clean",
37
- "cb": "bun run clean && bun run build",
36
+ "cl": "bun run clean",
38
37
  "clean": "rm -rfv dist *.tsbuildinfo",
39
- "d": "bun run build:es && bun",
38
+ "format": "prettier --write \"src/**/*.ts\"",
39
+ "lint": "eslint src/ --ext .ts",
40
40
  "t": "bun run test",
41
- "test": "bun test",
41
+ "test": "ALWATR_DEBUG=0 bun test",
42
42
  "w": "bun run watch",
43
43
  "watch": "bun run watch:ts & bun run watch:es",
44
44
  "watch:es": "bun run build:es --watch",
45
45
  "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
46
46
  },
47
47
  "files": [
48
- "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
48
+ "dist",
49
+ "src/**/*.ts",
50
+ "!src/**/*.test.ts",
49
51
  "README.md",
50
- "LICENSE",
51
- "!demo/**/*",
52
- "!**/*.test.js"
52
+ "LICENSE"
53
53
  ],
54
54
  "publishConfig": {
55
55
  "access": "public"
@@ -79,6 +79,5 @@
79
79
  "utility",
80
80
  "utils"
81
81
  ],
82
- "prettier": "@alwatr/prettier-config",
83
- "gitHead": "95bb13efd0a5f485c6b09f1a911b99492017aed1"
82
+ "gitHead": "38fb79dd8b6cf48108ae6492ecd7a285c7633e9b"
84
83
  }
package/src/main.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {newFlatomise} from '@alwatr/flatomise';
2
2
 
3
- import type {} from '@alwatr/type-helper';
4
3
 
5
4
  /**
6
5
  * A queue that executes async tasks in order like mutex and semaphore methodology