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

feat(io/streams): Propagate cancel in readableStreamFromIterable() #1274

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

nayeemrmn
Copy link
Contributor

Passes readable stream cancellations to the underlying iterator when applicable.

const readable = readableStreamFromIterable(async function* () {
  try {
    yield "foo";
  } catch (error) {
    console.log(error); // Error: Cancelled by consumer.
  }
}());
const reader = readable.getReader();
console.log(await reader.read()); // { value: "foo", done: false }
await reader.cancel(new Error("Cancelled by consumer."));

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice!

assertEquals(await reader.read(), { value: "foo", done: false });
const cancelReason = new Error("Cancelled by consumer.");
await reader.cancel(cancelReason);
assertEquals(generatorError, cancelReason);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kt3k kt3k merged commit 6881696 into denoland:main Sep 14, 2021
@nayeemrmn nayeemrmn deleted the readable-stream-from-iterable-cancel branch September 14, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants