fix(VirtualStream): Fix issue in VirtualStream to handle null values during data writing.

This commit is contained in:
Philipp Kunz 2024-10-16 02:47:35 +02:00
parent 11c6559e33
commit 050966cd6f
3 changed files with 14 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## 2024-10-16 - 3.1.7 - fix(VirtualStream)
Fix issue in VirtualStream to handle null values during data writing.
- Ensured writableStream closes gracefully when null values are encountered.
- Added a null check before writing data to the writableStream to prevent errors.
## 2024-10-16 - 3.1.6 - fix(VirtualStream)
Fix backpressure handling in VirtualStream workOnQueue method

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedrequest',
version: '3.1.6',
version: '3.1.7',
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
}

View File

@ -399,11 +399,17 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
public async writeToWebstream(writableStreamArg: WritableStream<T>) {
const writer = writableStreamArg.getWriter();
while(this.keepAlive || this.receiveBackpressuredArray.checkHasItems()) {
await writer.write(await this.fetchData());
const value = await this.fetchData();
if (value === null) {
writableStreamArg.close();
break;
}
await writer.write(value);
}
}
public async close() {
this.sendData(null);
this.keepAlive = false;
}
}