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

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

View File

@ -1,5 +1,11 @@
# Changelog
## 2024-10-16 - 3.2.1 - fix(core)
Fix the order of operations in SmartDuplex _read method to ensure proper waiting for items.
- Adjusted the order of reading function execution and waiting for items in the SmartDuplex _read method.
- Fixed potential issues with stream data processing timing.
## 2024-10-16 - 3.2.0 - feat(SmartDuplex)
Added method to create SmartDuplex from a WebReadableStream.

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstream',
version: '3.2.0',
version: '3.2.1',
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
}

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();

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstream',
version: '3.2.0',
version: '3.2.1',
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
}