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

What happens to iterators after they error? #92

Open
RubenVerborgh opened this issue Sep 21, 2022 · 4 comments
Open

What happens to iterators after they error? #92

RubenVerborgh opened this issue Sep 21, 2022 · 4 comments
Labels
Milestone

Comments

@RubenVerborgh
Copy link
Owner

Should they be closed? Destroyed? Should there be a special stated for iterators that errored?
Or is recovery possible?

@jeswr
Copy link
Collaborator

jeswr commented Sep 23, 2022

My proposal is that

  1. Iterators from this library only error during a .read() call (or whilst in flowing mode when a data listener is attached).
  2. If there is at least one error listener - the error is forwarded. Otherwise an error is thrown.
  3. Following the error event the iterator is destroyed.

@RubenVerborgh
Copy link
Owner Author

  • Iterators from this library only error during a .read() call (or whilst in flowing mode when a data listener is attached).

I don't think we can enforce that; errors can happen at any random moment.
So when not in flowing mode, the iterator might be preparing something that results in an error.
And there is no guarantee (!) that the read method will be called, so the error would be lost.
Plus we need to be able to accept Node.js Readable, which are allowed to random error.

  • If there is at least one error listener - the error is forwarded. Otherwise an error is thrown.

Check.

  • Following the error event the iterator is destroyed.

Note that proper destruction might not be possible anymore after error, but yes, best-effort destruction seems appropriate. I wonder if there are scenarios where we would not want this though; @rubensworks?

@rubensworks
Copy link
Collaborator

Following the error event the iterator is destroyed.

Note that proper destruction might not be possible anymore after error, but yes, best-effort destruction seems appropriate. I wonder if there are scenarios where we would not want this though; @rubensworks?

Yes, I think destroying after error makes sense (at least as default). Can't think of any cases atm where you wouldn't want this.

@jeswr
Copy link
Collaborator

jeswr commented Sep 23, 2022

I don't think we can enforce that; errors can happen at any random moment. So when not in flowing mode, the iterator might be preparing something that results in an error.

Rather than immediately forwarding an error we can store a pendingError and to set the iterator to readable at that time; the next read() call would then cause the emission of the pendingError.

And there is no guarantee (!) that the read method will be called, so the error would be lost.

Hmm good point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants