@naturalcycles/nodejs-lib 15.37.0 → 15.37.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Predicate } from '@naturalcycles/js-lib/types';
|
|
1
|
+
import type { NonNegativeInteger, Predicate } from '@naturalcycles/js-lib/types';
|
|
2
2
|
import { Pipeline } from '../pipeline.js';
|
|
3
3
|
import type { TransformOptions, TransformTyped } from '../stream.model.js';
|
|
4
4
|
/**
|
|
@@ -11,4 +11,4 @@ import type { TransformOptions, TransformTyped } from '../stream.model.js';
|
|
|
11
11
|
*
|
|
12
12
|
* @experimental
|
|
13
13
|
*/
|
|
14
|
-
export declare function transformMultiFork<T>(splitPredicate: Predicate<T>, fn: (pipeline: Pipeline<T
|
|
14
|
+
export declare function transformMultiFork<T>(splitPredicate: Predicate<T>, fn: (pipeline: Pipeline<T>, splitIndex: NonNegativeInteger) => Promise<void>, opt?: TransformOptions): TransformTyped<T, T>;
|
|
@@ -60,19 +60,19 @@ export function transformMultiFork(splitPredicate, fn, opt = {}) {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
function createNewFork() {
|
|
63
|
-
const
|
|
63
|
+
const currentSplitIndex = splitIndex;
|
|
64
64
|
const readable = createReadable([], {}, () => {
|
|
65
65
|
// `_read` is called
|
|
66
66
|
if (!lock)
|
|
67
67
|
return;
|
|
68
68
|
// We had a lock - let's Resume
|
|
69
|
-
logger.debug(`TransformMultiFork(${
|
|
69
|
+
logger.debug(`TransformMultiFork(${currentSplitIndex}): resume`);
|
|
70
70
|
const lockCopy = lock;
|
|
71
71
|
lock = undefined;
|
|
72
72
|
lockCopy.resolve();
|
|
73
73
|
});
|
|
74
|
-
void fn(Pipeline.from(readable)).then(() => {
|
|
75
|
-
logger.log(`TransformMultiFork(${
|
|
74
|
+
void fn(Pipeline.from(readable), currentSplitIndex).then(() => {
|
|
75
|
+
logger.log(`TransformMultiFork(${currentSplitIndex}): done`);
|
|
76
76
|
});
|
|
77
77
|
return readable;
|
|
78
78
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
2
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
|
|
3
3
|
import { type DeferredPromise, pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
|
|
4
|
-
import type { Predicate } from '@naturalcycles/js-lib/types'
|
|
4
|
+
import type { NonNegativeInteger, Predicate } from '@naturalcycles/js-lib/types'
|
|
5
5
|
import { Pipeline } from '../pipeline.js'
|
|
6
6
|
import { createReadable } from '../readable/createReadable.js'
|
|
7
7
|
import type { ReadableTyped, TransformOptions, TransformTyped } from '../stream.model.js'
|
|
@@ -18,7 +18,7 @@ import type { ReadableTyped, TransformOptions, TransformTyped } from '../stream.
|
|
|
18
18
|
*/
|
|
19
19
|
export function transformMultiFork<T>(
|
|
20
20
|
splitPredicate: Predicate<T>,
|
|
21
|
-
fn: (pipeline: Pipeline<T
|
|
21
|
+
fn: (pipeline: Pipeline<T>, splitIndex: NonNegativeInteger) => Promise<void>,
|
|
22
22
|
opt: TransformOptions = {},
|
|
23
23
|
): TransformTyped<T, T> {
|
|
24
24
|
const { objectMode = true, highWaterMark } = opt
|
|
@@ -76,20 +76,20 @@ export function transformMultiFork<T>(
|
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
function createNewFork(): ReadableTyped<T> {
|
|
79
|
-
const
|
|
79
|
+
const currentSplitIndex = splitIndex
|
|
80
80
|
|
|
81
81
|
const readable = createReadable<T>([], {}, () => {
|
|
82
82
|
// `_read` is called
|
|
83
83
|
if (!lock) return
|
|
84
84
|
// We had a lock - let's Resume
|
|
85
|
-
logger.debug(`TransformMultiFork(${
|
|
85
|
+
logger.debug(`TransformMultiFork(${currentSplitIndex}): resume`)
|
|
86
86
|
const lockCopy = lock
|
|
87
87
|
lock = undefined
|
|
88
88
|
lockCopy.resolve()
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
void fn(Pipeline.from<T>(readable)).then(() => {
|
|
92
|
-
logger.log(`TransformMultiFork(${
|
|
91
|
+
void fn(Pipeline.from<T>(readable), currentSplitIndex).then(() => {
|
|
92
|
+
logger.log(`TransformMultiFork(${currentSplitIndex}): done`)
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
return readable
|