fix(core): Fix the order of operations in SmartDuplex _read method to ensure proper waiting for items.

This commit is contained in:
2024-10-16 01:54:39 +02:00
parent 30f2facd59
commit 40e8e06ff1
4 changed files with 10 additions and 4 deletions

View File

@@ -105,11 +105,11 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
public async _read(size: number): Promise<void> {
this.debugLog(`${this.options.name}: read was called`);
await this.backpressuredArray.waitForItems();
this.debugLog(`${this.options.name}: successfully waited for items.`);
if (this.options.readFunction) {
await this.options.readFunction();
}
await this.backpressuredArray.waitForItems();
this.debugLog(`${this.options.name}: successfully waited for items.`);
let canPushMore = true;
while (this.backpressuredArray.data.length > 0 && canPushMore) {
const nextChunk = this.backpressuredArray.shift();