@altano/tiny-async-pool 4.0.2 → 4.0.4

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/README.md CHANGED
@@ -11,7 +11,8 @@ The goal of this library is to use the native async iterator (ES9), native async
11
11
  `doWorkAndYield` runs multiple promise-returning & async functions in a limited concurrency pool. It rejects immediately as soon as one of the promises rejects. It calls the iterator function as soon as possible (under concurrency limit). It returns an async iterator that yields as soon as a promise completes (under concurrency limit). For example:
12
12
 
13
13
  ```js
14
- const timeout = (ms) => new Promise((resolve) => setTimeout(() => resolve(ms), ms));
14
+ const timeout = (ms) =>
15
+ new Promise((resolve) => setTimeout(() => resolve(ms), ms));
15
16
 
16
17
  for await (const ms of doWorkAndYield(2, [1000, 5000, 3000, 2000], timeout)) {
17
18
  console.log(ms);
package/dist/doWork.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import { IterableItem } from "./doWorkAndYield.js";
2
-
3
- //#region src/doWork.d.ts
4
2
  /**
5
- * Process items from `iterable` in batches.
6
- */
7
- declare function doWork<TIn, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
8
- //#endregion
9
- export { doWork };
3
+ * Process items from `iterable` in batches.
4
+ */
5
+ export declare function doWork<TIn, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
10
6
  //# sourceMappingURL=doWork.d.ts.map
package/dist/doWork.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { doWorkAndYield } from "./doWorkAndYield.js";
2
2
 
3
- //#region src/doWork.ts
3
+ // src/doWork.ts
4
4
  /**
5
5
  * Process items from `iterable` in batches.
6
6
  */
@@ -8,6 +8,5 @@ async function doWork(concurrentCount, iterable, iteratorFn) {
8
8
  for await (const _result of doWorkAndYield(concurrentCount, iterable, iteratorFn));
9
9
  }
10
10
 
11
- //#endregion
12
11
  export { doWork };
13
12
  //# sourceMappingURL=doWork.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"doWork.js","names":[],"sources":["../src/doWork.ts"],"sourcesContent":["import { doWorkAndYield, type IterableItem } from \"./doWorkAndYield.js\";\n\n/**\n * Process items from `iterable` in batches.\n */\nexport async function doWork<TIn, TIterable extends Iterable<TIn>>(\n /**\n * The size of the batch of work, or, how many times `iteratorFn` will be\n * called in parallel.\n */\n concurrentCount: number,\n /**\n * An iterable that contains the items that should be passed to `iteratorFn`.\n */\n iterable: TIterable,\n /**\n * The async callback function that does the work. Will be passed items from\n * `iterable`. Promise returned must not resolve to a value, as it will be\n * ignored.\n */\n iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<void>,\n): Promise<void> {\n for await (const _result of doWorkAndYield(\n concurrentCount,\n iterable,\n iteratorFn,\n )) {\n // no-op\n }\n}\n"],"mappings":";;;;;;AAKA,eAAsB,OAKpB,iBAIA,UAMA,YAIe;AACf,YAAW,MAAM,WAAW,eAC1B,iBACA,UACA,WACD"}
1
+ {"version":3,"file":"doWork.js","names":[],"sources":["../src/doWork.ts"],"sourcesContent":["import { doWorkAndYield, type IterableItem } from \"./doWorkAndYield.js\";\n\n/**\n * Process items from `iterable` in batches.\n */\nexport async function doWork<TIn, TIterable extends Iterable<TIn>>(\n /**\n * The size of the batch of work, or, how many times `iteratorFn` will be\n * called in parallel.\n */\n concurrentCount: number,\n /**\n * An iterable that contains the items that should be passed to `iteratorFn`.\n */\n iterable: TIterable,\n /**\n * The async callback function that does the work. Will be passed items from\n * `iterable`. Promise returned must not resolve to a value, as it will be\n * ignored.\n */\n iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<void>,\n): Promise<void> {\n for await (const _result of doWorkAndYield(\n concurrentCount,\n iterable,\n iteratorFn,\n )) {\n // no-op\n }\n}\n"],"mappings":";;;;;;AAKA,eAAsB,OAKpB,iBAIA,UAMA,YAIe;CACf,WAAW,MAAM,WAAW,eAC1B,iBACA,UACA,UACF;AAGF"}
@@ -1,10 +1,7 @@
1
- //#region src/doWorkAndYield.d.ts
2
- type IterableItem<T> = T extends Iterable<infer R> ? R : never;
1
+ export type IterableItem<T> = T extends Iterable<infer R> ? R : never;
3
2
  /**
4
- * Process items from `iterable` in batches and yield the result of each call to
5
- * `iteratorFn`
6
- */
7
- declare function doWorkAndYield<TIn, TOut, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<TOut>): AsyncGenerator<Awaited<TOut>, void, unknown>;
8
- //#endregion
9
- export { IterableItem, doWorkAndYield };
3
+ * Process items from `iterable` in batches and yield the result of each call to
4
+ * `iteratorFn`
5
+ */
6
+ export declare function doWorkAndYield<TIn, TOut, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<TOut>): AsyncGenerator<Awaited<TOut>, void, unknown>;
10
7
  //# sourceMappingURL=doWorkAndYield.d.ts.map
@@ -1,4 +1,4 @@
1
- //#region src/doWorkAndYield.ts
1
+ // src/doWorkAndYield.ts
2
2
  /**
3
3
  * Process items from `iterable` in batches and yield the result of each call to
4
4
  * `iteratorFn`
@@ -18,6 +18,5 @@ async function* doWorkAndYield(concurrentCount, iterable, iteratorFn) {
18
18
  while (executing.size) yield await consume();
19
19
  }
20
20
 
21
- //#endregion
22
21
  export { doWorkAndYield };
23
22
  //# sourceMappingURL=doWorkAndYield.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"doWorkAndYield.js","names":[],"sources":["../src/doWorkAndYield.ts"],"sourcesContent":["type ExecutingPromise<TOut> = Promise<[ExecutingPromise<TOut>, TOut]>;\nexport type IterableItem<T> = T extends Iterable<infer R> ? R : never;\n\n/**\n * Process items from `iterable` in batches and yield the result of each call to\n * `iteratorFn`\n */\nexport async function* doWorkAndYield<\n TIn,\n TOut,\n TIterable extends Iterable<TIn>,\n>(\n /**\n * The size of the batch of work, or, how many times `iteratorFn` will be\n * called in parallel.\n */\n concurrentCount: number,\n /**\n * An iterable that contains the items that should be passed to `iteratorFn`.\n */\n iterable: TIterable,\n /**\n * The async callback function that does the work. Will be passed items from\n * `iterable`.\n */\n iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<TOut>,\n): AsyncGenerator<Awaited<TOut>, void, unknown> {\n const executing = new Set<ExecutingPromise<TOut>>();\n\n async function consume(): Promise<TOut> {\n const [promise, value] = await Promise.race(executing);\n executing.delete(promise);\n return value;\n }\n\n for (const item of iterable) {\n // Create a [Promise, Value] tuple so that we can access the original Promise\n // when `Promise.race(...)` resolves\n const result = iteratorFn(item as IterableItem<TIterable>, iterable);\n const promise = result.then((value): [ExecutingPromise<TOut>, TOut] => [\n promise,\n value,\n ]);\n executing.add(promise);\n if (executing.size >= concurrentCount) {\n yield await consume();\n }\n }\n while (executing.size) {\n yield await consume();\n }\n}\n"],"mappings":";;;;;AAOA,gBAAuB,eASrB,iBAIA,UAKA,YAI8C;CAC9C,MAAM,4BAAY,IAAI,KAA6B;CAEnD,eAAe,UAAyB;EACtC,MAAM,CAAC,SAAS,SAAS,MAAM,QAAQ,KAAK,UAAU;AACtD,YAAU,OAAO,QAAQ;AACzB,SAAO;;AAGT,MAAK,MAAM,QAAQ,UAAU;EAI3B,MAAM,UADS,WAAW,MAAiC,SAAS,CAC7C,MAAM,UAA0C,CACrE,SACA,MACD,CAAC;AACF,YAAU,IAAI,QAAQ;AACtB,MAAI,UAAU,QAAQ,gBACpB,OAAM,MAAM,SAAS;;AAGzB,QAAO,UAAU,KACf,OAAM,MAAM,SAAS"}
1
+ {"version":3,"file":"doWorkAndYield.js","names":[],"sources":["../src/doWorkAndYield.ts"],"sourcesContent":["type ExecutingPromise<TOut> = Promise<[ExecutingPromise<TOut>, TOut]>;\nexport type IterableItem<T> = T extends Iterable<infer R> ? R : never;\n\n/**\n * Process items from `iterable` in batches and yield the result of each call to\n * `iteratorFn`\n */\nexport async function* doWorkAndYield<\n TIn,\n TOut,\n TIterable extends Iterable<TIn>,\n>(\n /**\n * The size of the batch of work, or, how many times `iteratorFn` will be\n * called in parallel.\n */\n concurrentCount: number,\n /**\n * An iterable that contains the items that should be passed to `iteratorFn`.\n */\n iterable: TIterable,\n /**\n * The async callback function that does the work. Will be passed items from\n * `iterable`.\n */\n iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<TOut>,\n): AsyncGenerator<Awaited<TOut>, void, unknown> {\n const executing = new Set<ExecutingPromise<TOut>>();\n\n async function consume(): Promise<TOut> {\n const [promise, value] = await Promise.race(executing);\n executing.delete(promise);\n return value;\n }\n\n for (const item of iterable) {\n // Create a [Promise, Value] tuple so that we can access the original Promise\n // when `Promise.race(...)` resolves\n const result = iteratorFn(item as IterableItem<TIterable>, iterable);\n const promise = result.then((value): [ExecutingPromise<TOut>, TOut] => [\n promise,\n value,\n ]);\n executing.add(promise);\n if (executing.size >= concurrentCount) {\n yield await consume();\n }\n }\n while (executing.size) {\n yield await consume();\n }\n}\n"],"mappings":";;;;;AAOA,gBAAuB,eASrB,iBAIA,UAKA,YAI8C;CAC9C,MAAM,4BAAY,IAAI,IAA4B;CAElD,eAAe,UAAyB;EACtC,MAAM,CAAC,SAAS,SAAS,MAAM,QAAQ,KAAK,SAAS;EACrD,UAAU,OAAO,OAAO;EACxB,OAAO;CACT;CAEA,KAAK,MAAM,QAAQ,UAAU;EAI3B,MAAM,UADS,WAAW,MAAiC,QACtC,CAAC,CAAC,MAAM,UAA0C,CACrE,SACA,KACF,CAAC;EACD,UAAU,IAAI,OAAO;EACrB,IAAI,UAAU,QAAQ,iBACpB,MAAM,MAAM,QAAQ;CAExB;CACA,OAAO,UAAU,MACf,MAAM,MAAM,QAAQ;AAExB"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { IterableItem, doWorkAndYield } from "./doWorkAndYield.js";
2
1
  import { doWork } from "./doWork.js";
2
+ import { IterableItem, doWorkAndYield } from "./doWorkAndYield.js";
3
3
  export { IterableItem, doWork, doWorkAndYield };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { doWorkAndYield } from "./doWorkAndYield.js";
2
1
  import { doWork } from "./doWork.js";
2
+ import { doWorkAndYield } from "./doWorkAndYield.js";
3
3
 
4
4
  export { doWork, doWorkAndYield };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altano/tiny-async-pool",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Run multiple promise-returning & async functions with limited concurrency using native ES9",
5
5
  "keywords": [
6
6
  "race",
@@ -21,11 +21,13 @@
21
21
  "license": "MIT",
22
22
  "author": {
23
23
  "name": "Alan Norbauer",
24
- "email": "altano@gmail.com",
24
+ "email": "alan@norbauer.com",
25
25
  "url": "https://alan.norbauer.com"
26
26
  },
27
27
  "contributors": [
28
- "Rafael Xavier de Souza"
28
+ {
29
+ "name": "Rafael Xavier de Souza"
30
+ }
29
31
  ],
30
32
  "sideEffects": false,
31
33
  "type": "module",
@@ -37,16 +39,16 @@
37
39
  "dist/**/*.d.ts"
38
40
  ],
39
41
  "devDependencies": {
40
- "@arethetypeswrong/cli": "^0.18.2",
41
- "@types/node": "^25.5.0",
42
- "@vitest/coverage-v8": "^4.1.0",
42
+ "@arethetypeswrong/cli": "^0.18.5",
43
+ "@types/node": "^26.6.6",
44
+ "@vitest/coverage-v8": "^5.1.0",
43
45
  "depcheck": "^1.4.7",
44
- "eslint": "^9.39.4",
45
- "prettier": "^3.8.1",
46
- "tsdown": "^0.21.4",
47
- "typescript": "^5.9.3",
48
- "vite": "^7.3.1",
49
- "vitest": "^4.1.0",
46
+ "eslint": "^10.14.0",
47
+ "prettier": "3.9.10",
48
+ "tsdown": "^0.23.5",
49
+ "typescript": "^6.0.3",
50
+ "vite": "^8.3.5",
51
+ "vitest": "^5.1.0",
50
52
  "@altano/build-config": "0.0.1",
51
53
  "@altano/testing": "0.0.1",
52
54
  "@altano/tsconfig": "0.0.1"
@@ -55,15 +57,15 @@
55
57
  "access": "public"
56
58
  },
57
59
  "scripts": {
58
- "build": "tsdown --config-loader unrun --config ../build-config/tsdown.config.node.ts",
60
+ "build": "tsdown",
59
61
  "check:exports": "attw --pack . --profile esm-only --quiet",
60
62
  "check:types:src": "tsc --noEmit",
61
63
  "check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
62
64
  "check:unused-dependencies": "depcheck",
63
65
  "clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
64
66
  "dev": "pnpm run build --watch",
65
- "format": "prettier --check src",
66
- "format:fix": "prettier --write src",
67
+ "format": "prettier --check .",
68
+ "format:fix": "prettier --write .",
67
69
  "lint": "eslint",
68
70
  "lint:fix": "TIMING=1 pnpm lint --fix",
69
71
  "lint:timing": "TIMING=1 pnpm lint",