@altano/tiny-async-pool 1.0.2 → 1.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 -4
- package/dist/doWork.d.ts +6 -0
- package/dist/doWorkAndYield.d.ts +22 -0
- package/dist/index.d.ts +3 -27
- package/package.json +29 -28
package/README.md
CHANGED
|
@@ -9,8 +9,7 @@ The goal of this library is to use the native async iterator (ES9), native async
|
|
|
9
9
|
`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:
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
const timeout = (ms) =>
|
|
13
|
-
new Promise((resolve) => setTimeout(() => resolve(ms), ms));
|
|
12
|
+
const timeout = (ms) => new Promise((resolve) => setTimeout(() => resolve(ms), ms));
|
|
14
13
|
|
|
15
14
|
for await (const ms of doWorkAndYield(2, [1000, 5000, 3000, 2000], timeout)) {
|
|
16
15
|
console.log(ms);
|
|
@@ -73,8 +72,7 @@ Iterator function that takes two arguments: the value of each iteration and the
|
|
|
73
72
|
The same as `doWorkAndYield(...)` but just returns a Promise that resolves when all work resolves/rejects, e.g.:
|
|
74
73
|
|
|
75
74
|
```js
|
|
76
|
-
const timeout = (ms) =>
|
|
77
|
-
new Promise((resolve) => setTimeout(() => resolve(ms), ms));
|
|
75
|
+
const timeout = (ms) => new Promise((resolve) => setTimeout(() => resolve(ms), ms));
|
|
78
76
|
|
|
79
77
|
await doWork(2, [1000, 5000, 3000, 2000], timeout);
|
|
80
78
|
```
|
package/dist/doWork.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { doWorkAndYield } from "./doWorkAndYield";
|
|
2
|
+
/**
|
|
3
|
+
* Process items from `iterable` in batches.
|
|
4
|
+
*/
|
|
5
|
+
export declare function doWork<TIn, TOut, TIterable extends Iterable<TIn>>(...args: Parameters<typeof doWorkAndYield<TIn, TOut, TIterable>>): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=doWork.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type IterableItem<T> = T extends Iterable<infer R> ? R : never;
|
|
2
|
+
/**
|
|
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>>(
|
|
7
|
+
/**
|
|
8
|
+
* The size of the batch of work, or, how many times `iteratorFn` will be
|
|
9
|
+
* called in parallel.
|
|
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>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=doWorkAndYield.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* `iteratorFn`
|
|
5
|
-
*/
|
|
6
|
-
declare function doWorkAndYield<TIn, TOut, TIterable extends Iterable<TIn>>(
|
|
7
|
-
/**
|
|
8
|
-
* The size of the batch of work, or, how many times `iteratorFn` will be
|
|
9
|
-
* called in parallel.
|
|
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>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Process items from `iterable` in batches.
|
|
24
|
-
*/
|
|
25
|
-
declare function doWork<TIn, TOut, TIterable extends Iterable<TIn>>(...args: Parameters<typeof doWorkAndYield<TIn, TOut, TIterable>>): Promise<void>;
|
|
26
|
-
|
|
27
|
-
export { doWork, doWorkAndYield };
|
|
1
|
+
export * from "./doWork";
|
|
2
|
+
export * from "./doWorkAndYield";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/tiny-async-pool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Run multiple promise-returning & async functions with limited concurrency using native ES9",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,18 +8,10 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"LICENSE-MIT",
|
|
11
|
-
"dist",
|
|
11
|
+
"dist/**/*.js",
|
|
12
|
+
"dist/**/*.d.ts",
|
|
12
13
|
"README.md"
|
|
13
14
|
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsup src/index.ts --format esm --dts",
|
|
16
|
-
"dev": "tsup src/index.ts --watch --format esm --dts",
|
|
17
|
-
"format": "prettier --write src",
|
|
18
|
-
"lint": "TIMING=1 eslint src/**/*.ts* --fix",
|
|
19
|
-
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
|
|
20
|
-
"test": "vitest --run",
|
|
21
|
-
"test:watch": "vitest"
|
|
22
|
-
},
|
|
23
15
|
"repository": {
|
|
24
16
|
"type": "git",
|
|
25
17
|
"url": "https://github.com/altano/npm-packages",
|
|
@@ -46,25 +38,34 @@
|
|
|
46
38
|
],
|
|
47
39
|
"license": "MIT",
|
|
48
40
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@types/
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"@typescript-eslint/parser": "^5.36.1",
|
|
54
|
-
"@vitest/ui": "^0.21.0",
|
|
41
|
+
"@types/node": "^20.11.25",
|
|
42
|
+
"@types/prettier": "^3.0.0",
|
|
43
|
+
"@vitest/ui": "^1.3.1",
|
|
44
|
+
"chai": "^4.4.1",
|
|
55
45
|
"chai-as-promised": "^7.1.1",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"typescript": "^4.8.2",
|
|
65
|
-
"vitest": "^0.21.0"
|
|
46
|
+
"eslint": "^8.57.0",
|
|
47
|
+
"mocha": "^10.3.0",
|
|
48
|
+
"prettier": "^3.2.5",
|
|
49
|
+
"tsup": "^8.0.2",
|
|
50
|
+
"typescript": "^5.4.2",
|
|
51
|
+
"vitest": "^1.3.1",
|
|
52
|
+
"@altano/tsconfig": "0.0.0",
|
|
53
|
+
"eslint-config-altano": "0.0.1"
|
|
66
54
|
},
|
|
67
55
|
"publishConfig": {
|
|
68
56
|
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup src/index.ts --format esm --onSuccess \"pnpm build:types\"",
|
|
60
|
+
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
61
|
+
"dev": "tsup src/index.ts --watch --format esm --dts",
|
|
62
|
+
"format": "prettier --check src",
|
|
63
|
+
"format:fix": "prettier --write src",
|
|
64
|
+
"lint": "eslint src/**/*.ts*",
|
|
65
|
+
"lint:timing": "TIMING=1 eslint src/**/*.ts*",
|
|
66
|
+
"lint:fix": "TIMING=1 eslint src/**/*.ts* --fix",
|
|
67
|
+
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
|
|
68
|
+
"test": "vitest --run",
|
|
69
|
+
"test:watch": "vitest"
|
|
69
70
|
}
|
|
70
|
-
}
|
|
71
|
+
}
|