stream: fix handling generators in Readable.from#32844
stream: fix handling generators in Readable.from#32844vadzim wants to merge 11 commits intonodejs:masterfrom
Conversation
mcollina
left a comment
There was a problem hiding this comment.
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 42It 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. |
ronag
left a comment
There was a problem hiding this comment.
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
|
@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