@altano/tiny-async-pool 4.0.0 → 4.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/doWork.d.ts CHANGED
@@ -1,14 +1,11 @@
1
1
  import { IterableItem } from "./doWorkAndYield.js";
2
2
 
3
3
  //#region src/doWork.d.ts
4
- /**
5
- * Process items from `iterable` in batches.
6
- */
4
+
7
5
  /**
8
6
  * Process items from `iterable` in batches.
9
7
  */
10
8
  declare function doWork<TIn, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
11
-
12
9
  //#endregion
13
10
  export { doWork };
14
11
  //# sourceMappingURL=doWork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doWork.js","names":["concurrentCount: number","iterable: TIterable","iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<void>"],"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,OAKpBA,iBAIAC,UAMAC,YAIe;AACf,YAAW,MAAM,WAAW,eAC1B,iBACA,UACA,WACD;AAGF"}
@@ -5,7 +5,6 @@ type IterableItem<T> = T extends Iterable<infer R> ? R : never;
5
5
  * `iteratorFn`
6
6
  */
7
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
-
9
8
  //#endregion
10
9
  export { IterableItem, doWorkAndYield };
11
10
  //# sourceMappingURL=doWorkAndYield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doWorkAndYield.js","names":["concurrentCount: number","iterable: TIterable","iteratorFn: (\n item: IterableItem<TIterable>,\n Iterable: TIterable,\n ) => Promise<TOut>"],"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,eASrBA,iBAIAC,UAKAC,YAI8C;CAC9C,MAAM,YAAY,IAAI;CAEtB,eAAe,UAAyB;EACtC,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,QAAQ,KAAK,UAAU;AACtD,YAAU,OAAO,QAAQ;AACzB,SAAO;CACR;AAED,MAAK,MAAM,QAAQ,UAAU;EAG3B,MAAM,SAAS,WAAW,MAAiC,SAAS;EACpE,MAAM,UAAU,OAAO,KAAK,CAAC,UAA0C,CACrE,SACA,KACD,EAAC;AACF,YAAU,IAAI,QAAQ;AACtB,MAAI,UAAU,QAAQ,gBACpB,OAAM,MAAM,SAAS;CAExB;AACD,QAAO,UAAU,KACf,OAAM,MAAM,SAAS;AAExB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altano/tiny-async-pool",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Run multiple promise-returning & async functions with limited concurrency using native ES9",
5
5
  "keywords": [
6
6
  "race",
@@ -33,6 +33,7 @@
33
33
  "types": "./dist/index.d.ts",
34
34
  "files": [
35
35
  "dist/**/*.js",
36
+ "dist/**/*.js.map",
36
37
  "dist/**/*.d.ts"
37
38
  ],
38
39
  "devDependencies": {
@@ -42,7 +43,7 @@
42
43
  "depcheck": "^1.4.7",
43
44
  "eslint": "^9.23.0",
44
45
  "prettier": "^3.5.3",
45
- "tsdown": "^0.12.3",
46
+ "tsdown": "^0.12.9",
46
47
  "typescript": "^5.8.2",
47
48
  "vite": "^6.2.6",
48
49
  "vitest": "^3.1.4",