spliterator 6.1.0 → 6.2.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 +18 -0
- package/out/index.d.ts +26 -25
- package/out/index.d.ts.map +1 -1
- package/out/index.js +26 -25
- package/out/index.js.map +1 -1
- package/out/lib/AsyncSpliterator.d.ts.map +1 -1
- package/out/lib/AsyncSpliterator.js +28 -0
- package/out/lib/AsyncSpliterator.js.map +1 -1
- package/out/lib/CharacterSequence.d.ts +16 -1
- package/out/lib/CharacterSequence.d.ts.map +1 -1
- package/out/lib/CharacterSequence.js +37 -0
- package/out/lib/CharacterSequence.js.map +1 -1
- package/out/lib/core/AsyncSpliterator.d.ts +227 -0
- package/out/lib/core/AsyncSpliterator.d.ts.map +1 -0
- package/out/lib/core/AsyncSpliterator.js +510 -0
- package/out/lib/core/AsyncSpliterator.js.map +1 -0
- package/out/lib/core/BufferController.d.ts +77 -0
- package/out/lib/core/BufferController.d.ts.map +1 -0
- package/out/lib/core/BufferController.js +118 -0
- package/out/lib/core/BufferController.js.map +1 -0
- package/out/lib/core/CharacterSequence.d.ts +72 -0
- package/out/lib/core/CharacterSequence.d.ts.map +1 -0
- package/out/lib/core/CharacterSequence.js +347 -0
- package/out/lib/core/CharacterSequence.js.map +1 -0
- package/out/lib/core/CompositeDataView.d.ts +111 -0
- package/out/lib/core/CompositeDataView.d.ts.map +1 -0
- package/out/lib/core/CompositeDataView.js +241 -0
- package/out/lib/core/CompositeDataView.js.map +1 -0
- package/out/lib/core/IndexQueue.d.ts +48 -0
- package/out/lib/core/IndexQueue.d.ts.map +1 -0
- package/out/lib/core/IndexQueue.js +111 -0
- package/out/lib/core/IndexQueue.js.map +1 -0
- package/out/lib/core/SlidingWindow.d.ts +47 -0
- package/out/lib/core/SlidingWindow.d.ts.map +1 -0
- package/out/lib/core/SlidingWindow.js +63 -0
- package/out/lib/core/SlidingWindow.js.map +1 -0
- package/out/lib/core/Spliterator.d.ts +96 -0
- package/out/lib/core/Spliterator.d.ts.map +1 -0
- package/out/lib/core/Spliterator.js +330 -0
- package/out/lib/core/Spliterator.js.map +1 -0
- package/out/lib/core/wasm_base64.d.ts +19 -0
- package/out/lib/core/wasm_base64.d.ts.map +1 -0
- package/out/lib/core/wasm_base64.js +19 -0
- package/out/lib/core/wasm_base64.js.map +1 -0
- package/out/lib/core/wasm_module.d.ts +57 -0
- package/out/lib/core/wasm_module.d.ts.map +1 -0
- package/out/lib/core/wasm_module.js +34 -0
- package/out/lib/core/wasm_module.js.map +1 -0
- package/out/lib/formats/CSVSpliterator.d.ts +131 -0
- package/out/lib/formats/CSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/CSVSpliterator.js +172 -0
- package/out/lib/formats/CSVSpliterator.js.map +1 -0
- package/out/lib/formats/JSONSpliterator.d.ts +44 -0
- package/out/lib/formats/JSONSpliterator.d.ts.map +1 -0
- package/out/lib/formats/JSONSpliterator.js +77 -0
- package/out/lib/formats/JSONSpliterator.js.map +1 -0
- package/out/lib/formats/PSVSpliterator.d.ts +21 -0
- package/out/lib/formats/PSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/PSVSpliterator.js +22 -0
- package/out/lib/formats/PSVSpliterator.js.map +1 -0
- package/out/lib/formats/TSVSpliterator.d.ts +21 -0
- package/out/lib/formats/TSVSpliterator.d.ts.map +1 -0
- package/out/lib/formats/TSVSpliterator.js +22 -0
- package/out/lib/formats/TSVSpliterator.js.map +1 -0
- package/out/lib/formats/TextSpliterator.d.ts +53 -0
- package/out/lib/formats/TextSpliterator.d.ts.map +1 -0
- package/out/lib/formats/TextSpliterator.js +67 -0
- package/out/lib/formats/TextSpliterator.js.map +1 -0
- package/out/lib/formats/XLSXSpliterator.d.ts +143 -0
- package/out/lib/formats/XLSXSpliterator.d.ts.map +1 -0
- package/out/lib/formats/XLSXSpliterator.js +161 -0
- package/out/lib/formats/XLSXSpliterator.js.map +1 -0
- package/out/lib/formats/casing.d.ts +27 -0
- package/out/lib/formats/casing.d.ts.map +1 -0
- package/out/lib/formats/casing.js +68 -0
- package/out/lib/formats/casing.js.map +1 -0
- package/out/lib/formats/row-emitters.d.ts +35 -0
- package/out/lib/formats/row-emitters.d.ts.map +1 -0
- package/out/lib/formats/row-emitters.js +50 -0
- package/out/lib/formats/row-emitters.js.map +1 -0
- package/out/lib/internal/shared.d.ts +155 -0
- package/out/lib/internal/shared.d.ts.map +1 -0
- package/out/lib/internal/shared.js +41 -0
- package/out/lib/internal/shared.js.map +1 -0
- package/out/lib/internal/utils.d.ts +37 -0
- package/out/lib/internal/utils.d.ts.map +1 -0
- package/out/lib/internal/utils.js +39 -0
- package/out/lib/internal/utils.js.map +1 -0
- package/out/lib/io/adaptive-source.d.ts +39 -0
- package/out/lib/io/adaptive-source.d.ts.map +1 -0
- package/out/lib/io/adaptive-source.js +95 -0
- package/out/lib/io/adaptive-source.js.map +1 -0
- package/out/lib/io/writer.d.ts +45 -0
- package/out/lib/io/writer.d.ts.map +1 -0
- package/out/lib/io/writer.js +57 -0
- package/out/lib/io/writer.js.map +1 -0
- package/out/lib/iterators/AsyncSequence.d.ts +180 -0
- package/out/lib/iterators/AsyncSequence.d.ts.map +1 -0
- package/out/lib/iterators/AsyncSequence.js +432 -0
- package/out/lib/iterators/AsyncSequence.js.map +1 -0
- package/out/lib/iterators/chunks.d.ts +20 -0
- package/out/lib/iterators/chunks.d.ts.map +1 -0
- package/out/lib/iterators/chunks.js +36 -0
- package/out/lib/iterators/chunks.js.map +1 -0
- package/out/lib/iterators/pivot.d.ts +30 -0
- package/out/lib/iterators/pivot.d.ts.map +1 -0
- package/out/lib/iterators/pivot.js +47 -0
- package/out/lib/iterators/pivot.js.map +1 -0
- package/out/lib/iterators/zip.d.ts +33 -0
- package/out/lib/iterators/zip.d.ts.map +1 -0
- package/out/lib/iterators/zip.js +59 -0
- package/out/lib/iterators/zip.js.map +1 -0
- package/out/lib/parallel/merge-async-iterators.d.ts +12 -0
- package/out/lib/parallel/merge-async-iterators.d.ts.map +1 -0
- package/out/lib/parallel/merge-async-iterators.js +39 -0
- package/out/lib/parallel/merge-async-iterators.js.map +1 -0
- package/out/lib/parallel/parallel-map-runtime.d.ts +22 -0
- package/out/lib/parallel/parallel-map-runtime.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-runtime.js +60 -0
- package/out/lib/parallel/parallel-map-runtime.js.map +1 -0
- package/out/lib/parallel/parallel-map-worker-entry.d.ts +11 -0
- package/out/lib/parallel/parallel-map-worker-entry.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-worker-entry.js +41 -0
- package/out/lib/parallel/parallel-map-worker-entry.js.map +1 -0
- package/out/lib/parallel/parallel-map-workers.d.ts +57 -0
- package/out/lib/parallel/parallel-map-workers.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map-workers.js +82 -0
- package/out/lib/parallel/parallel-map-workers.js.map +1 -0
- package/out/lib/parallel/parallel-map.d.ts +28 -0
- package/out/lib/parallel/parallel-map.d.ts.map +1 -0
- package/out/lib/parallel/parallel-map.js +30 -0
- package/out/lib/parallel/parallel-map.js.map +1 -0
- package/out/lib/parallel/segment-runtime.d.ts +27 -0
- package/out/lib/parallel/segment-runtime.d.ts.map +1 -0
- package/out/lib/parallel/segment-runtime.js +41 -0
- package/out/lib/parallel/segment-runtime.js.map +1 -0
- package/out/lib/parallel/segment-worker-entry.d.ts +10 -0
- package/out/lib/parallel/segment-worker-entry.d.ts.map +1 -0
- package/out/lib/parallel/segment-worker-entry.js +59 -0
- package/out/lib/parallel/segment-worker-entry.js.map +1 -0
- package/out/lib/parallel/segment-workers.d.ts +56 -0
- package/out/lib/parallel/segment-workers.d.ts.map +1 -0
- package/out/lib/parallel/segment-workers.js +110 -0
- package/out/lib/parallel/segment-workers.js.map +1 -0
- package/out/lib/parallel/segments.d.ts +31 -0
- package/out/lib/parallel/segments.d.ts.map +1 -0
- package/out/lib/parallel/segments.js +52 -0
- package/out/lib/parallel/segments.js.map +1 -0
- package/out/lib/wasm_base64.d.ts +4 -1
- package/out/lib/wasm_base64.d.ts.map +1 -1
- package/out/lib/wasm_base64.js +4 -1
- package/out/lib/wasm_base64.js.map +1 -1
- package/out/lib/wasm_module.d.ts +15 -0
- package/out/lib/wasm_module.d.ts.map +1 -1
- package/out/lib/wasm_module.js +2 -1
- package/out/lib/wasm_module.js.map +1 -1
- package/out/node/cli/commands/csv.d.ts +113 -0
- package/out/node/cli/commands/csv.d.ts.map +1 -1
- package/out/node/cli/commands/csv.js +34 -36
- package/out/node/cli/commands/csv.js.map +1 -1
- package/out/node/cli/commands/iterate.d.ts +92 -0
- package/out/node/cli/commands/iterate.d.ts.map +1 -1
- package/out/node/cli/commands/iterate.js +26 -28
- package/out/node/cli/commands/iterate.js.map +1 -1
- package/out/node/cli/commands/parallel.d.ts +102 -0
- package/out/node/cli/commands/parallel.d.ts.map +1 -0
- package/out/node/cli/commands/parallel.js +426 -0
- package/out/node/cli/commands/parallel.js.map +1 -0
- package/out/node/cli/index.js +5 -0
- package/out/node/cli/index.js.map +1 -1
- package/out/node/cli/spec.d.ts +51 -0
- package/out/node/cli/spec.d.ts.map +1 -0
- package/out/node/cli/spec.js +78 -0
- package/out/node/cli/spec.js.map +1 -0
- package/out/node/cli/utils.d.ts +36 -18
- package/out/node/cli/utils.d.ts.map +1 -1
- package/out/node/cli/utils.js +48 -39
- package/out/node/cli/utils.js.map +1 -1
- package/out/node/fs/index.d.ts +1 -1
- package/out/node/fs/index.d.ts.map +1 -1
- package/out/node/fs/index.js +1 -1
- package/out/node/fs/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Group an iterable's values into arrays of `size`, with a shorter final batch if the collection does not divide
|
|
8
|
+
* evenly.
|
|
9
|
+
*
|
|
10
|
+
* Distinct from `Iterator.prototype.take`, which yields the first `size` _values_. Named for the [iterator chunking
|
|
11
|
+
* proposal](https://github.com/tc39/proposal-iterator-chunking).
|
|
12
|
+
*
|
|
13
|
+
* @param collection The collection to batch.
|
|
14
|
+
* @param size The size of each batch.
|
|
15
|
+
*
|
|
16
|
+
* @yields Each batch of values.
|
|
17
|
+
* @see {@linkcode AsyncSequence.chunks} for the asynchronous form.
|
|
18
|
+
*/
|
|
19
|
+
export function* chunks(collection, size) {
|
|
20
|
+
const normalized = Math.trunc(size);
|
|
21
|
+
if (!Number.isFinite(normalized) || normalized < 1) {
|
|
22
|
+
throw new RangeError(`chunks(${size}): size must be a positive finite number`);
|
|
23
|
+
}
|
|
24
|
+
let batch = [];
|
|
25
|
+
for (const item of collection) {
|
|
26
|
+
batch.push(item);
|
|
27
|
+
if (batch.length === normalized) {
|
|
28
|
+
yield batch;
|
|
29
|
+
batch = [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (batch.length) {
|
|
33
|
+
yield batch;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=chunks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.js","sourceRoot":"","sources":["../../../lib/iterators/chunks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CAAI,UAAuB,EAAE,IAAY;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,UAAU,CAAC,UAAU,IAAI,0CAA0C,CAAC,CAAA;IAC/E,CAAC;IAED,IAAI,KAAK,GAAQ,EAAE,CAAA;IAEnB,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,KAAK,CAAA;YAEX,KAAK,GAAG,EAAE,CAAA;QACX,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,KAAK,CAAA;IACZ,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Given an iterable of values, maps each value to a record of the value and the result of the callback.
|
|
8
|
+
*
|
|
9
|
+
* This is a convenience function when an iterable needs mapping to an object-like structure.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const iterable = ["a", "b", "c"]
|
|
13
|
+
* const result = pivot(iterable, (value) => value.toUpperCase())
|
|
14
|
+
*
|
|
15
|
+
* // { a: "A", b: "B", c: "C" }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @category Collections
|
|
19
|
+
* @category Object
|
|
20
|
+
*/
|
|
21
|
+
export declare function pivot<T extends PropertyKey, C extends (value: T) => Promise<unknown> | unknown>(
|
|
22
|
+
/**
|
|
23
|
+
* The iterable to pivot.
|
|
24
|
+
*/
|
|
25
|
+
iterable: Iterable<T>,
|
|
26
|
+
/**
|
|
27
|
+
* The callback to transform each value.
|
|
28
|
+
*/
|
|
29
|
+
callback: C): ReturnType<C> extends PromiseLike<infer U> ? Promise<Record<T, U>> : Record<T, ReturnType<C>>;
|
|
30
|
+
//# sourceMappingURL=pivot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pivot.d.ts","sourceRoot":"","sources":["../../../lib/iterators/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAC9F;;GAEG;AACH,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrB;;GAEG;AACH,QAAQ,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CA6B/F"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Given an iterable of values, maps each value to a record of the value and the result of the callback.
|
|
8
|
+
*
|
|
9
|
+
* This is a convenience function when an iterable needs mapping to an object-like structure.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const iterable = ["a", "b", "c"]
|
|
13
|
+
* const result = pivot(iterable, (value) => value.toUpperCase())
|
|
14
|
+
*
|
|
15
|
+
* // { a: "A", b: "B", c: "C" }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @category Collections
|
|
19
|
+
* @category Object
|
|
20
|
+
*/
|
|
21
|
+
export function pivot(
|
|
22
|
+
/**
|
|
23
|
+
* The iterable to pivot.
|
|
24
|
+
*/
|
|
25
|
+
iterable,
|
|
26
|
+
/**
|
|
27
|
+
* The callback to transform each value.
|
|
28
|
+
*/
|
|
29
|
+
callback) {
|
|
30
|
+
const entries = [];
|
|
31
|
+
let foundThenable = false;
|
|
32
|
+
for (const value of iterable) {
|
|
33
|
+
const result = callback(value);
|
|
34
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
35
|
+
foundThenable = true;
|
|
36
|
+
}
|
|
37
|
+
entries.push([value, result]);
|
|
38
|
+
}
|
|
39
|
+
if (foundThenable) {
|
|
40
|
+
return Promise.all(entries.map(([key, value]) => {
|
|
41
|
+
return Promise.resolve(value).then((resolvedValue) => [key, resolvedValue]);
|
|
42
|
+
})).then(Object.fromEntries);
|
|
43
|
+
}
|
|
44
|
+
const pivotedRecord = Object.fromEntries(entries);
|
|
45
|
+
return pivotedRecord;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=pivot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pivot.js","sourceRoot":"","sources":["../../../lib/iterators/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK;AACpB;;GAEG;AACH,QAAqB;AACrB;;GAEG;AACH,QAAW;IAEX,MAAM,OAAO,GAA8B,EAAE,CAAA;IAC7C,IAAI,aAAa,GAAG,KAAK,CAAA;IAEzB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YAC9D,aAAa,GAAG,IAAI,CAAA;QACrB,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAuB,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,GAAG,CACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,aAAa,CAAU,CAAC,CAAA;QACrF,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAEE,CAAA;IAC5B,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAEjD,OAAO,aAEoB,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
export type Zipped<T, U> = [a: T | undefined, b: U | undefined, idx: number];
|
|
7
|
+
export type ZippedEntries<Z> = Z extends Zipped<infer T, infer U> ? [T, U] : never;
|
|
8
|
+
export declare function zippedEntries<T, U>(zipped: Zipped<T, U>): ZippedEntries<Zipped<T, U>>;
|
|
9
|
+
/**
|
|
10
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
11
|
+
*
|
|
12
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
13
|
+
*
|
|
14
|
+
* @param a The first iterable to zip.
|
|
15
|
+
* @param b The second iterable to zip.
|
|
16
|
+
*
|
|
17
|
+
* @yields Pairs of elements from the two iterables.
|
|
18
|
+
* @see {@linkcode zipAsync} for the asynchronous version.
|
|
19
|
+
*/
|
|
20
|
+
export declare function zipSync<T, U>(a: Iterable<T>, b: Iterable<U>): Generator<Zipped<T, U>>;
|
|
21
|
+
/**
|
|
22
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
23
|
+
*
|
|
24
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
25
|
+
*
|
|
26
|
+
* @param a The first iterable to zip.
|
|
27
|
+
* @param b The second iterable to zip.
|
|
28
|
+
*
|
|
29
|
+
* @yields Pairs of elements from the two iterables.
|
|
30
|
+
* @see {@linkcode zipSync} for the synchronous version.
|
|
31
|
+
*/
|
|
32
|
+
export declare function zipAsync<T, U>(a: AsyncIterable<T> | Iterable<T>, b: AsyncIterable<U> | Iterable<U>): AsyncGenerator<[a: T | undefined, b: U | undefined, idx: number]>;
|
|
33
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../../lib/iterators/zip.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAE5E,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAA;AAElF,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAErF;AAED;;;;;;;;;;GAUG;AACH,wBAAiB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAkBtF;AAED;;;;;;;;;;GAUG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACnC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACjC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAC/B,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAkBnE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
export function zippedEntries(zipped) {
|
|
7
|
+
return zipped.slice(0, 2);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
11
|
+
*
|
|
12
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
13
|
+
*
|
|
14
|
+
* @param a The first iterable to zip.
|
|
15
|
+
* @param b The second iterable to zip.
|
|
16
|
+
*
|
|
17
|
+
* @yields Pairs of elements from the two iterables.
|
|
18
|
+
* @see {@linkcode zipAsync} for the asynchronous version.
|
|
19
|
+
*/
|
|
20
|
+
export function* zipSync(a, b) {
|
|
21
|
+
const aIterator = a[Symbol.iterator]();
|
|
22
|
+
const bIterator = b[Symbol.iterator]();
|
|
23
|
+
let index = 0;
|
|
24
|
+
while (true) {
|
|
25
|
+
const { done: aDone, value: aValue } = aIterator.next();
|
|
26
|
+
const { done: bDone, value: bValue } = bIterator.next();
|
|
27
|
+
if (aDone && bDone) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
yield [aValue, bValue, index];
|
|
31
|
+
index++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Given two iterables, zip them together into a single iterable which yields pairs of elements.
|
|
36
|
+
*
|
|
37
|
+
* If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
|
|
38
|
+
*
|
|
39
|
+
* @param a The first iterable to zip.
|
|
40
|
+
* @param b The second iterable to zip.
|
|
41
|
+
*
|
|
42
|
+
* @yields Pairs of elements from the two iterables.
|
|
43
|
+
* @see {@linkcode zipSync} for the synchronous version.
|
|
44
|
+
*/
|
|
45
|
+
export async function* zipAsync(a, b) {
|
|
46
|
+
const aIterator = Symbol.asyncIterator in a ? a[Symbol.asyncIterator]() : a[Symbol.iterator]();
|
|
47
|
+
const bIterator = Symbol.asyncIterator in b ? b[Symbol.asyncIterator]() : b[Symbol.iterator]();
|
|
48
|
+
let index = 0;
|
|
49
|
+
while (true) {
|
|
50
|
+
const { done: aDone, value: aValue } = await aIterator.next();
|
|
51
|
+
const { done: bDone, value: bValue } = await bIterator.next();
|
|
52
|
+
if (aDone && bDone) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
yield [aValue, bValue, index];
|
|
56
|
+
index++;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.js","sourceRoot":"","sources":["../../../lib/iterators/zip.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,UAAU,aAAa,CAAO,MAAoB;IACvD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAgC,CAAA;AACzD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,SAAS,CAAC,CAAC,OAAO,CAAO,CAAc,EAAE,CAAc;IAC5D,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IACtC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IAEtC,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;QACvD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;QAEvD,IAAI,KAAK,IA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+
* Merge several async iterables, pulling from **all of them concurrently** and yielding each value as soon as it
|
|
8
|
+
* arrives (completion order, not source order). An error from any source rejects; remaining sources are returned
|
|
9
|
+
* (cancelled) on completion, error, or early break.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeAsyncIterators<R>(sources: Array<AsyncIterable<R>>): AsyncIterableIterator<R>;
|
|
12
|
+
//# sourceMappingURL=merge-async-iterators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-async-iterators.d.ts","sourceRoot":"","sources":["../../../lib/parallel/merge-async-iterators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAuB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CA6BxG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Merge several async iterables, pulling from **all of them concurrently** and yielding each value as soon as it
|
|
8
|
+
* arrives (completion order, not source order). An error from any source rejects; remaining sources are returned
|
|
9
|
+
* (cancelled) on completion, error, or early break.
|
|
10
|
+
*/
|
|
11
|
+
export async function* mergeAsyncIterators(sources) {
|
|
12
|
+
const advance = (it) => it.next().then((result) => ({ it, result }));
|
|
13
|
+
const pending = new Map();
|
|
14
|
+
for (const source of sources) {
|
|
15
|
+
const it = source[Symbol.asyncIterator]();
|
|
16
|
+
pending.set(it, advance(it));
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
while (pending.size) {
|
|
20
|
+
const { it, result } = await Promise.race(pending.values());
|
|
21
|
+
if (result.done) {
|
|
22
|
+
pending.delete(it);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
yield result.value;
|
|
26
|
+
pending.set(it, advance(it));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
// Stop any iterators we didn't drain (early break / error). Swallow rejections from their
|
|
32
|
+
// in-flight `next()` so they don't surface as unhandled.
|
|
33
|
+
for (const promise of pending.values()) {
|
|
34
|
+
void promise.catch(() => { });
|
|
35
|
+
}
|
|
36
|
+
await Promise.allSettled(Array.from(pending.keys(), (it) => it.return?.()));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=merge-async-iterators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-async-iterators.js","sourceRoot":"","sources":["../../../lib/parallel/merge-async-iterators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CAAI,OAAgC;IAC7E,MAAM,OAAO,GAAG,CAAC,EAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IACtF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkF,CAAA;IAEzG,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QACzC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;YAE3D,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACnB,CAAC;iBAAM,CAAC;gBACP,MAAM,MAAM,CAAC,KAAK,CAAA;gBAClB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;YAAS,CAAC;QACV,0FAA0F;QAC1F,yDAAyD;QACzD,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC7B,CAAC;QAED,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5E,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Transport-agnostic core of `parallelMap` — a record-dispatch worker pool. `runPool` keeps every
|
|
7
|
+
* worker busy mapping batches pulled from one shared source, with no `worker_threads` dependency so it
|
|
8
|
+
* unit-tests against fake workers.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* One pool slot. `process` ships a batch to its worker and resolves with that batch's results.
|
|
12
|
+
*/
|
|
13
|
+
export interface PoolWorker<T, R> {
|
|
14
|
+
process(batch: T[]): Promise<R[]>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Drive a pool of `workers` over `source`: each worker loops — pull a batch, map it, emit results — until the source is
|
|
18
|
+
* exhausted. Results stream out in completion order (a worker's whole batch yields before it pulls the next, which
|
|
19
|
+
* bounds in-flight work to the pool size). A worker error propagates and tears the pool down.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runPool<T, R>(workers: Array<PoolWorker<T, R>>, source: AsyncIterable<T> | Iterable<T>, batchSize: number): AsyncIterableIterator<R>;
|
|
22
|
+
//# sourceMappingURL=parallel-map-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map-runtime.d.ts","sourceRoot":"","sources":["../../../lib/parallel/parallel-map-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC;IAC/B,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAA;CACjC;AA+CD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC3B,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAChC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,SAAS,EAAE,MAAM,GACf,qBAAqB,CAAC,CAAC,CAAC,CAgB1B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Transport-agnostic core of `parallelMap` — a record-dispatch worker pool. `runPool` keeps every
|
|
7
|
+
* worker busy mapping batches pulled from one shared source, with no `worker_threads` dependency so it
|
|
8
|
+
* unit-tests against fake workers.
|
|
9
|
+
*/
|
|
10
|
+
import { mergeAsyncIterators } from "./merge-async-iterators.js";
|
|
11
|
+
/**
|
|
12
|
+
* Serialize pulls from `source` into batches of up to `batchSize`. Returns a `next()` that is safe to call concurrently
|
|
13
|
+
* (each call awaits the prior pull) — concurrent worker loops share one source without racing the underlying iterator.
|
|
14
|
+
* Resolves `null` once the source is exhausted.
|
|
15
|
+
*/
|
|
16
|
+
function makeBatcher(source, batchSize) {
|
|
17
|
+
const iterator = Symbol.asyncIterator in source
|
|
18
|
+
? source[Symbol.asyncIterator]()
|
|
19
|
+
: source[Symbol.iterator]();
|
|
20
|
+
let chain = Promise.resolve();
|
|
21
|
+
let exhausted = false;
|
|
22
|
+
return () => {
|
|
23
|
+
const pull = chain.then(async () => {
|
|
24
|
+
if (exhausted)
|
|
25
|
+
return null;
|
|
26
|
+
const batch = [];
|
|
27
|
+
while (batch.length < batchSize) {
|
|
28
|
+
const { value, done } = await iterator.next();
|
|
29
|
+
if (done) {
|
|
30
|
+
exhausted = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
batch.push(value);
|
|
34
|
+
}
|
|
35
|
+
return batch.length ? batch : null;
|
|
36
|
+
});
|
|
37
|
+
// Keep the chain alive regardless of this pull's outcome so the next call still serializes.
|
|
38
|
+
chain = pull.then(() => undefined, () => undefined);
|
|
39
|
+
return pull;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Drive a pool of `workers` over `source`: each worker loops — pull a batch, map it, emit results — until the source is
|
|
44
|
+
* exhausted. Results stream out in completion order (a worker's whole batch yields before it pulls the next, which
|
|
45
|
+
* bounds in-flight work to the pool size). A worker error propagates and tears the pool down.
|
|
46
|
+
*/
|
|
47
|
+
export function runPool(workers, source, batchSize) {
|
|
48
|
+
const nextBatch = makeBatcher(source, batchSize);
|
|
49
|
+
async function* workerLoop(worker) {
|
|
50
|
+
for (;;) {
|
|
51
|
+
const batch = await nextBatch();
|
|
52
|
+
if (batch === null)
|
|
53
|
+
return;
|
|
54
|
+
const results = await worker.process(batch);
|
|
55
|
+
yield* results;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return mergeAsyncIterators(workers.map((worker) => workerLoop(worker)));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=parallel-map-runtime.js.map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IAAI,CAAA;IACZ,CAAC,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACtB,OAAgC,EAChC,MAAsC,EACtC,SAAiB;IAEjB,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAEhD,KAAK,SAAS,CAAC,CAAC,UAAU,CAAC,MAAwB;QAClD,SAAS,CAAC;YACT,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAA;YAE/B,IAAI,KAAK,KAAK,IAAI;gBAAE,OAAM;YAE1B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAE3C,KAAK,CAAC,CAAC,OAAO,CAAA;QACf,CAAC;IACF,CAAC;IAED,OAAO,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Runs inside a worker thread (spawned by parallelMap). Imports the handler module once (top-level =
|
|
7
|
+
* per-worker init), then maps each dispatched batch and posts the results back. Processes one batch at
|
|
8
|
+
* a time — the pool never dispatches the next until this batch's result returns.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=parallel-map-worker-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map-worker-entry.d.ts","sourceRoot":"","sources":["../../../lib/parallel/parallel-map-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Runs inside a worker thread (spawned by parallelMap). Imports the handler module once (top-level =
|
|
7
|
+
* per-worker init), then maps each dispatched batch and posts the results back. Processes one batch at
|
|
8
|
+
* a time — the pool never dispatches the next until this batch's result returns.
|
|
9
|
+
*/
|
|
10
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
11
|
+
const data = workerData;
|
|
12
|
+
const port = parentPort;
|
|
13
|
+
let nextIndex = 0;
|
|
14
|
+
const handlerReady = import(data.handlerUrl).then((mod) => mod.handleItem ?? mod.default);
|
|
15
|
+
port.on("message", async (msg) => {
|
|
16
|
+
const message = msg;
|
|
17
|
+
if (message?.type !== "batch")
|
|
18
|
+
return;
|
|
19
|
+
try {
|
|
20
|
+
const handleItem = await handlerReady;
|
|
21
|
+
if (typeof handleItem !== "function") {
|
|
22
|
+
throw new TypeError(`Worker module ${data.handlerUrl} has no handleItem export.`);
|
|
23
|
+
}
|
|
24
|
+
const results = [];
|
|
25
|
+
const transfer = [];
|
|
26
|
+
for (const item of message.batch) {
|
|
27
|
+
const result = await handleItem(item, { index: nextIndex++ });
|
|
28
|
+
if (result === undefined)
|
|
29
|
+
continue;
|
|
30
|
+
results.push(result);
|
|
31
|
+
if (result instanceof Uint8Array) {
|
|
32
|
+
transfer.push(result.buffer);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
port.postMessage({ type: "result", results }, transfer);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
port.postMessage({ type: "error", message: error instanceof Error ? error.message : String(error) });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=parallel-map-worker-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map-worker-entry.js","sourceRoot":"","sources":["../../../lib/parallel/parallel-map-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,E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;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACrG,CAAC;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Per-item handler a parallelMapWorkers worker module exports. `index` is per-worker monotonic.
|
|
8
|
+
*/
|
|
9
|
+
export type ParallelHandler<T = unknown, R = unknown> = (item: T, ctx: {
|
|
10
|
+
index: number;
|
|
11
|
+
}) => R | Uint8Array | undefined | Promise<R | Uint8Array | undefined>;
|
|
12
|
+
export interface ParallelMapWorkersOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Worker module path/URL exporting `handleItem(item, ctx)`. Top-level code = per-worker init.
|
|
15
|
+
*/
|
|
16
|
+
worker: string | URL;
|
|
17
|
+
/**
|
|
18
|
+
* Number of worker threads in the pool. Keep it SMALL for I/O- or memory-bound handlers (per-row DB lookups, large
|
|
19
|
+
* shared datasets): throughput typically peaks at ~2–3 and _degrades_ past that as workers contend for the shared
|
|
20
|
+
* resource — only CPU-bound handlers scale toward the core count. Also bounded by RAM (each worker re-inits its
|
|
21
|
+
* deps). Sweep it for your workload rather than defaulting to `availableParallelism()`.
|
|
22
|
+
*/
|
|
23
|
+
concurrency: number;
|
|
24
|
+
/**
|
|
25
|
+
* Items per dispatched batch. @default 64
|
|
26
|
+
*/
|
|
27
|
+
batchSize?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Forwarded to every worker via `workerData.userData` (must be structured-cloneable).
|
|
30
|
+
*/
|
|
31
|
+
workerData?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
|
|
35
|
+
* dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
|
|
36
|
+
* async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
|
|
37
|
+
* `Uint8Array` is transferred zero-copy.
|
|
38
|
+
*
|
|
39
|
+
* **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
|
|
40
|
+
* cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
|
|
41
|
+
* string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
|
|
42
|
+
* per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
|
|
43
|
+
* milliseconds, benchmark against the single-threaded version before adopting.
|
|
44
|
+
*
|
|
45
|
+
* **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
|
|
46
|
+
* anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
|
|
47
|
+
* contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
|
|
48
|
+
* CPU-bound per-row work (pure compute) scales out toward the core count.
|
|
49
|
+
*
|
|
50
|
+
* All workers are terminated on completion, error, or early `return()`.
|
|
51
|
+
*
|
|
52
|
+
* @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
|
|
53
|
+
* thread boundary and this takes a module path instead.
|
|
54
|
+
* @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parallelMapWorkers<T, R = unknown>(source: AsyncIterable<T> | Iterable<T>, options: ParallelMapWorkersOptions): AsyncIterableIterator<R>;
|
|
57
|
+
//# sourceMappingURL=parallel-map-workers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map-workers.d.ts","sourceRoot":"","sources":["../../../lib/parallel/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CACvD,IAAI,EAAE,CAAC,EACP,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,KAClB,CAAC,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAErE,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAqCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAChD,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,yBAAyB,GAChC,qBAAqB,CAAC,CAAC,CAAC,CAyB1B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { Worker } from "node:worker_threads";
|
|
7
|
+
import { runPool } from "./parallel-map-runtime.js";
|
|
8
|
+
/**
|
|
9
|
+
* Wrap a worker as a pool slot: dispatch one batch, await its result. One batch in flight at a time.
|
|
10
|
+
*/
|
|
11
|
+
function workerHandle(worker) {
|
|
12
|
+
let pending = null;
|
|
13
|
+
const settle = (fn) => {
|
|
14
|
+
if (!pending)
|
|
15
|
+
return;
|
|
16
|
+
const p = pending;
|
|
17
|
+
pending = null;
|
|
18
|
+
fn(p);
|
|
19
|
+
};
|
|
20
|
+
worker.on("message", (msg) => {
|
|
21
|
+
if (msg?.type === "result") {
|
|
22
|
+
settle((p) => p.resolve(msg.results));
|
|
23
|
+
}
|
|
24
|
+
else if (msg?.type === "error") {
|
|
25
|
+
settle((p) => p.reject(new Error(msg.message)));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
worker.on("error", (error) => settle((p) => p.reject(error instanceof Error ? error : new Error(String(error)))));
|
|
29
|
+
return {
|
|
30
|
+
process(batch) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
pending = { resolve, reject };
|
|
33
|
+
worker.postMessage({ type: "batch", batch });
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
|
|
40
|
+
* dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
|
|
41
|
+
* async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
|
|
42
|
+
* `Uint8Array` is transferred zero-copy.
|
|
43
|
+
*
|
|
44
|
+
* **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
|
|
45
|
+
* cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
|
|
46
|
+
* string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
|
|
47
|
+
* per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
|
|
48
|
+
* milliseconds, benchmark against the single-threaded version before adopting.
|
|
49
|
+
*
|
|
50
|
+
* **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
|
|
51
|
+
* anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
|
|
52
|
+
* contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
|
|
53
|
+
* CPU-bound per-row work (pure compute) scales out toward the core count.
|
|
54
|
+
*
|
|
55
|
+
* All workers are terminated on completion, error, or early `return()`.
|
|
56
|
+
*
|
|
57
|
+
* @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
|
|
58
|
+
* thread boundary and this takes a module path instead.
|
|
59
|
+
* @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
|
|
60
|
+
*/
|
|
61
|
+
export function parallelMapWorkers(source, options) {
|
|
62
|
+
const handlerUrl = options.worker instanceof URL ? options.worker.href : new URL(options.worker, `file://${process.cwd()}/`).href;
|
|
63
|
+
const concurrency = Math.max(1, Math.floor(options.concurrency));
|
|
64
|
+
const batchSize = options.batchSize ?? 64;
|
|
65
|
+
const entryUrl = new URL("./parallel-map-worker-entry.js", import.meta.url);
|
|
66
|
+
const workers = [];
|
|
67
|
+
async function* run() {
|
|
68
|
+
try {
|
|
69
|
+
const pool = Array.from({ length: concurrency }, () => {
|
|
70
|
+
const worker = new Worker(entryUrl, { workerData: { handlerUrl, userData: options.workerData } });
|
|
71
|
+
workers.push(worker);
|
|
72
|
+
return workerHandle(worker);
|
|
73
|
+
});
|
|
74
|
+
yield* runPool(pool, source, batchSize);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return run();
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=parallel-map-workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map-workers.js","sourceRoot":"","sources":["../../../lib/parallel/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAmB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAgCpE;;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AAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QAC/D,CAAC;IACF,CAAC;IAED,OAAO,GAAG,EAAE,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { AsyncSequence, type ParallelMapSequenceOptions } from "../iterators/AsyncSequence.js";
|
|
7
|
+
/**
|
|
8
|
+
* Map an iterable through a callback with up to `concurrency` calls in flight, yielding in **completion order** — not
|
|
9
|
+
* input order.
|
|
10
|
+
*
|
|
11
|
+
* The callback is a closure, so every call runs on the caller's thread. This overlaps _latency_ — file reads, network
|
|
12
|
+
* round-trips, anything that spends its time waiting — and does nothing for CPU-bound work, which still occupies the
|
|
13
|
+
* one thread it always did.
|
|
14
|
+
*
|
|
15
|
+
* **Concurrency is not core count.** Work that contends for a shared resource (one disk, one socket pool, one on-disk
|
|
16
|
+
* database) peaks _low_ — often ~2–3 — and then degrades. Sweep it.
|
|
17
|
+
*
|
|
18
|
+
* @param source The collection to map.
|
|
19
|
+
* @param fn The callback, receiving `(value, counter)`.
|
|
20
|
+
* @param options Concurrency ceiling and optional abort signal.
|
|
21
|
+
*
|
|
22
|
+
* @yields Each result, in completion order.
|
|
23
|
+
* @see {@linkcode parallelMapWorkers} to run the handler on worker threads instead — it takes a module path rather than
|
|
24
|
+
* a closure, because a closure cannot cross a thread boundary.
|
|
25
|
+
* @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parallelMap<T, U>(source: AsyncIterable<T> | Iterable<T>, fn: (value: T, counter: number) => U | PromiseLike<U>, options: ParallelMapSequenceOptions): AsyncSequence<U>;
|
|
28
|
+
//# sourceMappingURL=parallel-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-map.d.ts","sourceRoot":"","sources":["../../../lib/parallel/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,KAAK,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AAE9F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACrD,OAAO,EAAE,0BAA0B,GACjC,aAAa,CAAC,CAAC,CAAC,CAElB"}
|