fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-13 18:19:11 +01:00
parent a6ab15bf1d
commit 9421c652a2
2 changed files with 13 additions and 11 deletions

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartstream', name: '@push.rocks/smartstream',
version: '3.0.21', version: '3.0.22',
description: 'simplifies access to node streams' description: 'simplifies access to node streams'
} }

View File

@ -3,7 +3,7 @@ import { Duplex, type DuplexOptions } from 'stream';
export interface IStreamTools { export interface IStreamTools {
truncate: () => void; truncate: () => void;
push: (pipeObject: any) => void; push: (pipeObject: any) => Promise<void>;
} }
export interface IStreamWriteFunction<T, rT> { export interface IStreamWriteFunction<T, rT> {
@ -80,8 +80,13 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
isTruncated = true; isTruncated = true;
callback(); callback();
}, },
push: (pushArg: TOutput) => { push: async (pushArg: TOutput) => {
this.backpressuredArray.push(pushArg); const canPushMore = this.backpressuredArray.push(pushArg);
if (!canPushMore) {
this.debugLog(`${this.options.name}: cannot push more`);
await this.backpressuredArray.waitForSpace();
this.debugLog(`${this.options.name}: can push more again`);
}
}, },
}; };
@ -93,12 +98,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
return; return;
} }
if (modifiedChunk) { if (modifiedChunk) {
const canPushMore = this.backpressuredArray.push(modifiedChunk); await tools.push(modifiedChunk);
if (!canPushMore) {
this.debugLog(`${this.options.name}: cannot push more`);
await this.backpressuredArray.waitForSpace();
this.debugLog(`${this.options.name}: can push more again`);
}
} }
callback(); callback();
writeDeferred.resolve(); writeDeferred.resolve();
@ -115,7 +115,9 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
if (this.options.finalFunction) { if (this.options.finalFunction) {
const tools: IStreamTools = { const tools: IStreamTools = {
truncate: () => callback(), truncate: () => callback(),
push: (pipeObject) => this.push(pipeObject), push: async (pipeObject) => {
this.push(pipeObject);
},
}; };
try { try {