Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
03c7150b6b | |||
83cd25d5a2 | |||
04d60e6a95 | |||
549719ede6 | |||
855663eea9 | |||
4d98915dbd |
18
changelog.md
18
changelog.md
@ -1,5 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-10-11 - 3.1.0 - feat(virtualstream)
|
||||
Enhance VirtualStream with optional closure when reading from webstream
|
||||
|
||||
- Added an optional parameter `closeAfterReading` to the `readFromWebstream` method.
|
||||
- The stream will close automatically after reading if `closeAfterReading` is set to true.
|
||||
|
||||
## 2024-10-11 - 3.0.33 - fix(test)
|
||||
Increase delay duration before stopping the server in test suite.
|
||||
|
||||
- Adjusted the delay time from 1000 ms to 10000 ms before stopping the server to ensure tests complete smoothly.
|
||||
|
||||
## 2024-09-06 - 3.0.32 - fix(virtualstream)
|
||||
Fix keep-alive loop handling and test cleanup
|
||||
|
||||
- Prevent unnecessary keep-alive loop from starting on the responding side
|
||||
- Add logging for keep-alive loop initiation in VirtualStream
|
||||
- Temporarily comment out stream close and tap forceful stop in test to avoid abrupt termination
|
||||
|
||||
## 2024-09-06 - 3.0.31 - fix(core)
|
||||
Updated dependencies and added close method to VirtualStream
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@api.global/typedrequest",
|
||||
"version": "3.0.31",
|
||||
"version": "3.1.0",
|
||||
"private": false,
|
||||
"description": "A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -98,11 +98,10 @@ tap.test('should allow VirtualStreams', async () => {
|
||||
const data = await generatedRequestingVS.fetchData();
|
||||
const decodedData = new TextDecoder().decode(data);
|
||||
expect(decodedData).toEqual('hello');
|
||||
newRequestingVS.close();
|
||||
});
|
||||
|
||||
tap.test('should end the server', async (toolsArg) => {
|
||||
await toolsArg.delayFor(1000);
|
||||
await toolsArg.delayFor(10000);
|
||||
await testServer.stop();
|
||||
await tap.stopForcefully();
|
||||
});
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.0.31',
|
||||
version: '3.1.0',
|
||||
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
|
||||
}
|
||||
|
@ -295,7 +295,11 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
|
||||
*/
|
||||
private async startKeepAliveLoop() {
|
||||
// initially wait for a second
|
||||
if (this.side === 'responding') {
|
||||
return;
|
||||
}
|
||||
await plugins.smartdelay.delayFor(0);
|
||||
console.log(`starting keepalive loop on side ${this.side}`);
|
||||
let counter = 0;
|
||||
keepAliveLoop: while (this.keepAlive) {
|
||||
await this.triggerKeepAlive();
|
||||
@ -359,7 +363,7 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
|
||||
* reads from a Readable and sends it to the other side
|
||||
* @param readableStreamArg
|
||||
*/
|
||||
public async readFromWebstream(readableStreamArg: ReadableStream<T>) {
|
||||
public async readFromWebstream(readableStreamArg: ReadableStream<T>, closeAfterReading = true) {
|
||||
const reader = readableStreamArg.getReader();
|
||||
let streamIsDone = false;
|
||||
while(!streamIsDone) {
|
||||
@ -369,6 +373,9 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
|
||||
}
|
||||
streamIsDone = done;
|
||||
}
|
||||
if (closeAfterReading) {
|
||||
await this.close();
|
||||
}
|
||||
}
|
||||
|
||||
public async writeToWebstream(writableStreamArg: WritableStream<T>) {
|
||||
|
Reference in New Issue
Block a user