@altano/tiny-async-pool 2.0.0 → 3.0.0

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
@@ -1,6 +1,6 @@
1
1
  # tiny-async-pool
2
2
 
3
- This is an ESM + TypeScript rewrite of [tiny-async-pool](https://www.npmjs.com/package/tiny-async-pool) by Rafael Xavier de Souza.
3
+ This is an ESM + TypeScript fork of [tiny-async-pool](https://www.npmjs.com/package/tiny-async-pool) by Rafael Xavier de Souza, with some added functionality.
4
4
 
5
5
  ## Why?
6
6
 
@@ -71,7 +71,9 @@ Iterator function that takes two arguments: the value of each iteration and the
71
71
 
72
72
  ### `doWork(concurrency, iterable, iteratorFn)`
73
73
 
74
- Like `doWorkAndYield(...)` but returns a Promise that resolves when all work resolves (or rejects immediately when any Promise rejects). Useful when you don't care about the return of `iteratorFn`, such as a worker pool where you do batch file proccessing and the workers produce a side effect instead of returning a value. For example, a batch file eraser:
74
+ Like `doWorkAndYield(...)` but with a simpler API. Useful when you don't care about the return value of `iteratorFn`, such as a worker pool where you do batch file proccessing and the workers produce a side effect instead of returning a value.
75
+
76
+ For example, a batch file eraser is as simple as:
75
77
 
76
78
  ```js
77
79
  const eraseFile = (path) => fs.unlink(path);
package/dist/doWork.d.ts CHANGED
@@ -2,7 +2,7 @@ import { type IterableItem } from "./doWorkAndYield";
2
2
  /**
3
3
  * Process items from `iterable` in batches.
4
4
  */
5
- export declare function doWork<TIn, TOut, TIterable extends Iterable<TIn>>(
5
+ export declare function doWork<TIn, TIterable extends Iterable<TIn>>(
6
6
  /**
7
7
  * The size of the batch of work, or, how many times `iteratorFn` will be
8
8
  * called in parallel.
package/dist/doWork.js ADDED
@@ -0,0 +1,12 @@
1
+ import { doWorkAndYield } from "./doWorkAndYield";
2
+ async function doWork(concurrentCount, iterable, iteratorFn) {
3
+ for await (const _result of doWorkAndYield(
4
+ concurrentCount,
5
+ iterable,
6
+ iteratorFn
7
+ )) {
8
+ }
9
+ }
10
+ export {
11
+ doWork
12
+ };
@@ -0,0 +1,25 @@
1
+ async function* doWorkAndYield(concurrentCount, iterable, iteratorFn) {
2
+ const executing = /* @__PURE__ */ new Set();
3
+ async function consume() {
4
+ const [promise, value] = await Promise.race(executing);
5
+ executing.delete(promise);
6
+ return value;
7
+ }
8
+ for (const item of iterable) {
9
+ const result = iteratorFn(item, iterable);
10
+ const promise = result.then((value) => [
11
+ promise,
12
+ value
13
+ ]);
14
+ executing.add(promise);
15
+ if (executing.size >= concurrentCount) {
16
+ yield await consume();
17
+ }
18
+ }
19
+ while (executing.size) {
20
+ yield await consume();
21
+ }
22
+ }
23
+ export {
24
+ doWorkAndYield
25
+ };
package/dist/index.js CHANGED
@@ -1,37 +1,2 @@
1
- // src/doWorkAndYield.ts
2
- async function* doWorkAndYield(concurrentCount, iterable, iteratorFn) {
3
- const executing = /* @__PURE__ */ new Set();
4
- async function consume() {
5
- const [promise, value] = await Promise.race(executing);
6
- executing.delete(promise);
7
- return value;
8
- }
9
- for (const item of iterable) {
10
- const result = iteratorFn(item, iterable);
11
- const promise = result.then((value) => [
12
- promise,
13
- value
14
- ]);
15
- executing.add(promise);
16
- if (executing.size >= concurrentCount) {
17
- yield await consume();
18
- }
19
- }
20
- while (executing.size) {
21
- yield await consume();
22
- }
23
- }
24
-
25
- // src/doWork.ts
26
- async function doWork(concurrentCount, iterable, iteratorFn) {
27
- for await (const _result of doWorkAndYield(
28
- concurrentCount,
29
- iterable,
30
- iteratorFn
31
- )) {
32
- }
33
- }
34
- export {
35
- doWork,
36
- doWorkAndYield
37
- };
1
+ export * from "./doWork";
2
+ export * from "./doWorkAndYield";
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "@altano/tiny-async-pool",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Run multiple promise-returning & async functions with limited concurrency using native ES9",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "types": "./dist/index.d.ts",
6
+ "exports": "./dist/index.js",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
9
  "files": [
10
- "LICENSE-MIT",
11
10
  "dist/**/*.js",
12
- "dist/**/*.d.ts",
13
- "README.md"
11
+ "dist/**/*.d.ts"
14
12
  ],
15
13
  "repository": {
16
14
  "type": "git",
@@ -39,33 +37,34 @@
39
37
  "license": "MIT",
40
38
  "devDependencies": {
41
39
  "@types/node": "^20.11.25",
42
- "@types/prettier": "^3.0.0",
40
+ "@vitest/coverage-v8": "^1.4.0",
43
41
  "@vitest/ui": "^1.3.1",
44
42
  "chai": "^4.4.1",
45
43
  "chai-as-promised": "^7.1.1",
46
44
  "eslint": "^8.57.0",
47
45
  "mocha": "^10.3.0",
48
46
  "prettier": "^3.2.5",
49
- "tsup": "^8.0.2",
50
47
  "typescript": "^5.4.2",
51
- "vitest": "^1.3.1",
48
+ "vitest": "^1.4.0",
52
49
  "@altano/tsconfig": "0.0.0",
53
- "eslint-config-altano": "0.0.1"
50
+ "eslint-config-altano": "0.0.0"
54
51
  },
55
52
  "publishConfig": {
56
53
  "access": "public"
57
54
  },
58
55
  "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",
56
+ "build": "tsup --config build-config/tsup.config.node.ts",
57
+ "build:types": "tsc --project tsconfig.declarations.json",
58
+ "clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
59
+ "dev": "pnpm run build --watch",
62
60
  "format": "prettier --check src",
63
61
  "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"
62
+ "lint": "eslint package.json src/**/*.ts*",
63
+ "lint:fix": "TIMING=1 pnpm lint --fix",
64
+ "lint:timing": "TIMING=1 pnpm lint",
65
+ "test:unit": "vitest --run",
66
+ "test:unit:watch": "vitest",
67
+ "typecheck:src": "tsc --noEmit",
68
+ "typecheck:test": "tsc --noEmit --project ./tests/tsconfig.json"
70
69
  }
71
70
  }
File without changes