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

Implement Channel.prototype.throw #2

Closed
brainkim opened this issue May 6, 2019 · 0 comments
Closed

Implement Channel.prototype.throw #2

brainkim opened this issue May 6, 2019 · 0 comments
Assignees

Comments

@brainkim
Copy link
Member

brainkim commented May 6, 2019

The AsyncIterator defines an optional throw method that can be used to make the iterator throw an error. This is useful when you have nested async iteration loops and you don’t want to wait for the child loop to terminate before continuing the parent loop, but you still want to propagate errors to avoid Promise rejections. Example:

for await (const a of iterator) {
  if (a.subscribe) {
    (async () => {
      for await (const b of a.subscribe()) {
        console.log(b);
      }
    // propagate errors to the parent
    })().catch((err) => iterator.throw(err));
  }
}

Figure out the rejection semantics for throw and how it interacts with next and return. My plan is for throw to close the channel with the error and await return. If the channel is already closed, should throw reject?

@brainkim brainkim pinned this issue May 6, 2019
@brainkim brainkim unpinned this issue May 6, 2019
@brainkim brainkim self-assigned this May 6, 2019
brainkim pushed a commit that referenced this issue Sep 28, 2019
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

No branches or pull requests

1 participant