-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
stream: fix handling generators in Readable.from #32844
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.
Good spot. I'm not sure needToClose
is required, just always call return()
in _destroy()
. Also, please add a test.
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.
Would you mind to add a unit test for this? Thanks
|
Here is a "desugared" pseudo version of for-of I got from Gus Caplan:
I think that's probably what we should aim for. As you've noticed the throw + return() part is tricky. |
Where do you see this? Maybe? |
I'm sorry, it's quite difficult for me to understand that pseudocode. // next returns ordinary value, done = false:
for(const x of {
[Symbol.iterator](){ return this },
next(){ console.log('next'); return { value: 42, done: false } },
return(){ console.log('return'); return { done: true } }
}) {
console.log(x)
break
}
// output:
// next
// 42
// return
// undefined
// next returns done = true:
for(const x of {
[Symbol.iterator](){ return this },
next(){ console.log('next'); return { value: 42, done: true } },
return(){ console.log('return'); return { done: true } }
}) {
console.log(x)
break
}
// output:
// next
// undefined
// next throws
for(const x of {
[Symbol.iterator](){ return this },
next(){ console.log('next'); throw 42 },
return(){ console.log('return'); return { done: true } }
}) {
console.log(x)
break
}
// output:
// next
// Uncaught 42 It seems that |
What do you want to illustrate with this?
Yes, that's what we are fixing in this PR? |
I mean
|
Ah, I think I understand what you mean. |
What happens if you do the same thing with async iterators? |
But then the problem with #32842 remains? I think looking at the for await..of would be relevant. |
Same thing happens if we use |
This comment has been minimized.
This comment has been minimized.
We still need to deal with buffer in readable stream. |
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.
LGTM once tests are added, good job!
I'll write the tests, though it can take some time cause I'm gonna cover all these mentioned edge cases. |
Also, please take a look at the commit guidelines. You should use |
Sure, I'll squash my draft commits into one when the job is done. |
I've added tests and it's allowed me to catch one more case. |
Actually the code does not look simpler) and the tests should remain in any case. |
426b1d6
to
6bddcf7
Compare
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.
LGTM
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.
lgtm
@ronag @mcollina Btw, actually the code didn't contain any I guess this bugfix could be applied to node@12. Does it make sense? |
Absolutely, in due time. It will be included in the closest release of 12.x after 2 weeks of being in 13.x. |
Landed in 8a3fa32 |
Hi, I don't understand why |
That is - if someone creates a stream, calls |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passescloses #32842