async #enqueueConcurrent(controller) {
const results = await Promise.allSettled(this.#concurrent);
- this.#concurrent.length = 0;
for (const r of results) {
if (r.status === 'rejected') {
if (r.reason instanceof Error) {
this.#enqueueRow(r.value, controller);
}
}
+ // Only clear these arrays AFTER all transform processing is complete. Otherwise downstream functions
+ // may not be able to access the row data.
+ this.#concurrent.length = 0;
+ this.#batch.length = 0;
}
/** @type {TransformerTransformCallback<Array<string>,Array<string>>} */
this.#batch.push(chunk);
if (this.#batch.length === this.#maxBatchSize) {
this.#concurrent.push(this.#wrappedFn(this.#batch));
- this.#batch.length = 0;
}
}
else {
{ name: 'Error', message: 'Not an error type' }
);
});
+ test('can batch row data', { concurrency: true }, async (t) => {
+ await createCSVMockStream([
+ ['columnA'],
+ ['1'],
+ ['2']
+ ])
+ .pipeThrough(new CSVTransformer(r => r, { maxBatchSize: 2 }))
+ .pipeTo(csvStreamEqualWritable([
+ ['columnA'],
+ ['1'],
+ ['2']
+ ]));
+ });
test('creates batch of 1 when maxBatchSize is equal to 1', { concurrency: true }, async (t) => {
const fn = t.mock.fn(b => b.map(r => r.map(f => Number(f) * 2)));
await createCSVMockStream([