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
fix: ensure asyncIterator call return() when fail at calling next() #447
fix: ensure asyncIterator call return() when fail at calling next() #447
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for this! I am just wondering why calling .return
is necessary here. If you throw from a running iterator it is destroyed anyways, a .return
call would be superfluous - right?
Nice point! I thought it would be necessary cause some custom async iterator implementations contain clear logic at It can be seen as the responsibility of implementations, but this problem can be prevented by the consumer of async iterator and this PR is about that prevention. |
I understand your point, but beware that neither As per MDN:
And then
Hinting that cleanups are to be done in the |
Yes, I also think Lines 847 to 854 in 611c223
Lines 137 to 151 in 611c223
Before 611c223, After that commit, thrown async iterator is removed from |
We only call I don't fully follow your last comment, how's this behavior different with 611c223? A further flaw with this PR is also that We must assume that if the async generator read loop exits/throws - its due to user intervention (either by calling |
Sorry for confusing. In short, Before 611c223 If throwing in After 611c223 If throwing in
That's the side effect I missed, thanks for checking! I think this PR should be closed because of the flaw above 😅. |
And this is how it should be. 😄 |
Yep I get it. Thanks for answering! |
This calls
.return()
of asyncIterator before remove it fromsubscriptions
.After microsoft/TypeScript#51297, error at
iterator.next()
infor await (... of iterator)
statement does not calliterator.return()
. This can cause asyncIterator not to be cleared and hang.