@altano/tiny-async-pool 4.0.2 → 4.0.3
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 +2 -1
- package/dist/doWork.d.ts +2 -3
- package/dist/doWork.js.map +1 -1
- package/dist/doWorkAndYield.d.ts +3 -3
- package/dist/doWorkAndYield.js.map +1 -1
- package/package.json +17 -15
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) =>
|
|
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,9 +1,8 @@
|
|
|
1
1
|
import { IterableItem } from "./doWorkAndYield.js";
|
|
2
|
-
|
|
3
2
|
//#region src/doWork.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* Process items from `iterable` in batches.
|
|
6
|
-
*/
|
|
4
|
+
* Process items from `iterable` in batches.
|
|
5
|
+
*/
|
|
7
6
|
declare function doWork<TIn, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
|
|
8
7
|
//#endregion
|
|
9
8
|
export { doWork };
|
package/dist/doWork.js.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/doWorkAndYield.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//#region src/doWorkAndYield.d.ts
|
|
2
2
|
type IterableItem<T> = T extends Iterable<infer R> ? R : never;
|
|
3
3
|
/**
|
|
4
|
-
* Process items from `iterable` in batches and yield the result of each call to
|
|
5
|
-
* `iteratorFn`
|
|
6
|
-
*/
|
|
4
|
+
* Process items from `iterable` in batches and yield the result of each call to
|
|
5
|
+
* `iteratorFn`
|
|
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
8
|
//#endregion
|
|
9
9
|
export { IterableItem, doWorkAndYield };
|
|
@@ -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,
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/tiny-async-pool",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
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": "
|
|
24
|
+
"email": "alan@norbauer.com",
|
|
25
25
|
"url": "https://alan.norbauer.com"
|
|
26
26
|
},
|
|
27
27
|
"contributors": [
|
|
28
|
-
|
|
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.
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@vitest/coverage-v8": "^4.1.
|
|
42
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
43
|
+
"@types/node": "^26.1.1",
|
|
44
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
43
45
|
"depcheck": "^1.4.7",
|
|
44
|
-
"eslint": "^9.39.
|
|
45
|
-
"prettier": "
|
|
46
|
-
"tsdown": "^0.
|
|
47
|
-
"typescript": "^
|
|
48
|
-
"vite": "^
|
|
49
|
-
"vitest": "^4.1.
|
|
46
|
+
"eslint": "^9.39.5",
|
|
47
|
+
"prettier": "3.9.6",
|
|
48
|
+
"tsdown": "^0.22.13",
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
|
+
"vite": "^8.1.5",
|
|
51
|
+
"vitest": "^4.1.10",
|
|
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
|
|
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
|
|
66
|
-
"format:fix": "prettier --write
|
|
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",
|