@altano/tiny-async-pool 3.0.2 → 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 +10 -20
- package/dist/doWork.js +10 -9
- package/dist/doWork.js.map +1 -0
- package/dist/doWorkAndYield.d.ts +9 -20
- package/dist/doWorkAndYield.js +22 -23
- package/dist/doWorkAndYield.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -2
- package/package.json +14 -13
package/dist/doWork.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* An iterable that contains the items that should be passed to `iteratorFn`.
|
|
13
|
-
*/
|
|
14
|
-
iterable: TIterable,
|
|
15
|
-
/**
|
|
16
|
-
* The async callback function that does the work. Will be passed items from
|
|
17
|
-
* `iterable`. Promise returned must not resolve to a value, as it will be
|
|
18
|
-
* ignored.
|
|
19
|
-
*/
|
|
20
|
-
iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
|
|
1
|
+
import { IterableItem } from "./doWorkAndYield.js";
|
|
2
|
+
|
|
3
|
+
//#region src/doWork.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Process items from `iterable` in batches.
|
|
7
|
+
*/
|
|
8
|
+
declare function doWork<TIn, TIterable extends Iterable<TIn>>(concurrentCount: number, iterable: TIterable, iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<void>): Promise<void>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { doWork };
|
|
21
11
|
//# sourceMappingURL=doWork.d.ts.map
|
package/dist/doWork.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { doWorkAndYield } from "./doWorkAndYield.js";
|
|
2
|
+
|
|
3
|
+
//#region src/doWork.ts
|
|
4
|
+
/**
|
|
5
|
+
* Process items from `iterable` in batches.
|
|
6
|
+
*/
|
|
2
7
|
async function doWork(concurrentCount, iterable, iteratorFn) {
|
|
3
|
-
|
|
4
|
-
concurrentCount,
|
|
5
|
-
iterable,
|
|
6
|
-
iteratorFn
|
|
7
|
-
)) {
|
|
8
|
-
}
|
|
8
|
+
for await (const _result of doWorkAndYield(concurrentCount, iterable, iteratorFn));
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { doWork };
|
|
13
|
+
//# sourceMappingURL=doWork.js.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"}
|
package/dist/doWorkAndYield.d.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
concurrentCount: number,
|
|
12
|
-
/**
|
|
13
|
-
* An iterable that contains the items that should be passed to `iteratorFn`.
|
|
14
|
-
*/
|
|
15
|
-
iterable: TIterable,
|
|
16
|
-
/**
|
|
17
|
-
* The async callback function that does the work. Will be passed items from
|
|
18
|
-
* `iterable`.
|
|
19
|
-
*/
|
|
20
|
-
iteratorFn: (item: IterableItem<TIterable>, Iterable: TIterable) => Promise<TOut>): AsyncGenerator<Awaited<TOut>, void, unknown>;
|
|
1
|
+
//#region src/doWorkAndYield.d.ts
|
|
2
|
+
type IterableItem<T> = T extends Iterable<infer R> ? R : never;
|
|
3
|
+
/**
|
|
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 };
|
|
21
10
|
//# sourceMappingURL=doWorkAndYield.d.ts.map
|
package/dist/doWorkAndYield.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
+
//#region src/doWorkAndYield.ts
|
|
2
|
+
/**
|
|
3
|
+
* Process items from `iterable` in batches and yield the result of each call to
|
|
4
|
+
* `iteratorFn`
|
|
5
|
+
*/
|
|
1
6
|
async function* doWorkAndYield(concurrentCount, iterable, iteratorFn) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (executing.size >= concurrentCount) {
|
|
16
|
-
yield await consume();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
while (executing.size) {
|
|
20
|
-
yield await consume();
|
|
21
|
-
}
|
|
7
|
+
const executing = new Set();
|
|
8
|
+
async function consume() {
|
|
9
|
+
const [promise, value] = await Promise.race(executing);
|
|
10
|
+
executing.delete(promise);
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
for (const item of iterable) {
|
|
14
|
+
const result = iteratorFn(item, iterable);
|
|
15
|
+
const promise = result.then((value) => [promise, value]);
|
|
16
|
+
executing.add(promise);
|
|
17
|
+
if (executing.size >= concurrentCount) yield await consume();
|
|
18
|
+
}
|
|
19
|
+
while (executing.size) yield await consume();
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { doWorkAndYield };
|
|
24
|
+
//# sourceMappingURL=doWorkAndYield.js.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/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IterableItem, doWorkAndYield } from "./doWorkAndYield.js";
|
|
2
|
+
import { doWork } from "./doWork.js";
|
|
3
|
+
export { IterableItem, doWork, doWorkAndYield };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/tiny-async-pool",
|
|
3
|
-
"version": "
|
|
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,29 +33,30 @@
|
|
|
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": {
|
|
39
|
-
"@arethetypeswrong/cli": "^0.
|
|
40
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
40
41
|
"@types/node": "^22.13.10",
|
|
41
|
-
"@vitest/coverage-v8": "^3.
|
|
42
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
42
43
|
"depcheck": "^1.4.7",
|
|
43
|
-
"eslint": "^9.
|
|
44
|
-
"prettier": "^3.
|
|
44
|
+
"eslint": "^9.23.0",
|
|
45
|
+
"prettier": "^3.5.3",
|
|
46
|
+
"tsdown": "^0.12.9",
|
|
45
47
|
"typescript": "^5.8.2",
|
|
46
|
-
"vite": "^6.2.
|
|
47
|
-
"vitest": "^3.
|
|
48
|
-
"@altano/build-config": "0.0.
|
|
49
|
-
"@altano/testing": "0.0.
|
|
50
|
-
"@altano/tsconfig": "0.0.
|
|
48
|
+
"vite": "^6.2.6",
|
|
49
|
+
"vitest": "^3.1.4",
|
|
50
|
+
"@altano/build-config": "0.0.1",
|
|
51
|
+
"@altano/testing": "0.0.1",
|
|
52
|
+
"@altano/tsconfig": "0.0.1"
|
|
51
53
|
},
|
|
52
54
|
"publishConfig": {
|
|
53
55
|
"access": "public"
|
|
54
56
|
},
|
|
55
57
|
"scripts": {
|
|
56
|
-
"build": "
|
|
57
|
-
"
|
|
58
|
-
"check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
58
|
+
"build": "tsdown --config ../build-config/tsdown.config.node.ts",
|
|
59
|
+
"check:exports": "attw --pack . --profile esm-only --quiet",
|
|
59
60
|
"check:types:src": "tsc --noEmit",
|
|
60
61
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
61
62
|
"check:unused-dependencies": "depcheck",
|