Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release stream-lock when closing the WebStreamReader #765

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/WebStreamReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class WebStreamReader extends AbstractStreamReader {
return 0;
}

public abort(): Promise<void> {
return this.reader.cancel();
public async abort(): Promise<void> {
await this.reader.cancel(); // Signals a loss of interest in the stream by a consumer
this.reader.releaseLock();
}
}
14 changes: 14 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,19 @@ describe('Node.js StreamReader', () => {

});

describe('WebStreamReader', () => {

it('abort() should release stream-lock', async () => {

const readableStream = stringToReadableStream('abc');
assert.isFalse(readableStream.locked, 'stream is unlocked before initializing tokenizer');

const webStreamReader = new WebStreamReader(readableStream);
assert.isTrue(readableStream.locked, 'stream is locked after initializing tokenizer');

await webStreamReader.abort();
assert.isFalse(readableStream.locked, 'stream is unlocked after closing tokenizer');
});
});
});

Loading