diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 7f1c5c3..5673d01 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartstream', - version: '3.0.27', + version: '3.0.28', description: 'simplifies access to node streams' } diff --git a/ts/smartstream.classes.smartduplex.ts b/ts/smartstream.classes.smartduplex.ts index dc4bbe2..2d5b02a 100644 --- a/ts/smartstream.classes.smartduplex.ts +++ b/ts/smartstream.classes.smartduplex.ts @@ -66,6 +66,15 @@ export class SmartDuplex extends Duplex { } } + public async backpressuredPush (pushArg: TOutput) { + 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`); + } + }; + private asyncWritePromiseObjectmap = new plugins.lik.ObjectMap>(); // Ensure the _write method types the chunk as TInput and encodes TOutput public async _write(chunk: TInput, encoding: string, callback: (error?: Error | null) => void) { @@ -81,13 +90,8 @@ export class SmartDuplex extends Duplex { callback(); }, push: async (pushArg: TOutput) => { - 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`); - } - }, + await this.backpressuredPush(pushArg); + } }; try {