-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Behavior of readablestreams changed in v10 #20520
Comments
I didn't check but I think behavior changed with #18994. |
The provided example is not a good way of using streams, because it will add a new The solution (also to the cp-file case) is to use I think this can be closed. |
That is not a problem, because of the semantics of Promises. You may call new Promise((resolve, reject) => {
resolve('resolve: ' + 1);
resolve('resolve: ' + 2);
resolve('resolve: ' + 3);
reject('reject: ' + 1);
reject('reject: ' + 2);
reject('reject: ' + 3);
})
.then(console.log)
.catch(console.error);
// outputs on node v9 and v10
resolve: 1 Please also note, that your suggestion (using const fs = require('fs');
const read = fs.createReadStream(__filename);
read.on('readable', () => {
read.once('data', chunk => {
console.log('data');
});
});
// nodejs v9
//=> data
// nodejs v10
//=> (no output) @mcollina Interestingly, your suggestion to use read.once('readable', () => {
read.on('data', chunk => {
console.log('data');
});
});
// nodejs v9 and v10
//=> data Thus, it seems |
Yes but it's useless overhead.
The suggestion was to use The behavior change introduced in #18994 is semver-major but it seems to work as intended. |
That PR is 3 years old and rather long. Moreover the discussion does not contain the words I'm not sure what your point is. It is unexpected, if |
It was a typo when referencing the issue. The "4" was missing at the end. I fixed that by editing the reference. |
@BridgeAR Thank you, for clarifying. But, please do not edit my comments in a way, so the discussion does not make sense for readers anymore. |
@schnittstabil my point is that cf5f986 seems to work as expected, specifically:
|
Ok, but both |
The difference is that if there is at least one listener for the |
Hi Maintainers!
This may be the same underlying issue as #20503 - I'm not confident enough in the node core space enough to tell.
This problem was first noticed in cp-file, a dependency of cpy, which is a dependency of one of my projects. A very distilled test case is:
This is a program that reads itself, by creating a read stream, waiting for it to be readable, and then assigning a data event listener. It prints
data
on all node versions < 10, but prints nothing on the Node v10.0.0 release.In situ, cp-file tries to ensure that a stream is readable before creating the destination directory and then calling
.pipe
to write the file to disk. As far as I can tell, Node v10 changes the behavior of readable streams such that data events are not emitted if you bind the data event listener after readable is emitted.The text was updated successfully, but these errors were encountered: