This program prints "END":
const s = new require('stream').PassThrough();
function readable()
{
console.log(this.read());
}
s.end();
setTimeout(function ()
{
s.on('readable', readable);
s.on('end', function ()
{
console.log("END");
});
}, 1000);
whereas this program does not:
const s = new require('stream').PassThrough();
function readable()
{
console.log(this.read());
}
s.on('readable', readable);
s.removeListener('readable', readable);
s.end();
setTimeout(function ()
{
s.on('end', function ()
{
console.log("END");
});
}, 1000);
The only difference is that a readable listener is added and then removed before the stream is ended.
My question is whether the behaviour should be the same, given that there is no readable listener in both cases when the stream is ended.
I can see in the code why: At https://github.com/nodejs/node/blob/v6.7.0/lib/_stream_readable.js#L696 readableListening is set to true but it's never reset to false if all readable listeners are removed.
Before making any changes however, I'd like to ask whether this is intended behaviour?
This program prints "END":
whereas this program does not:
The only difference is that a
readablelistener is added and then removed before the stream is ended.My question is whether the behaviour should be the same, given that there is no
readablelistener in both cases when the stream is ended.I can see in the code why: At https://github.com/nodejs/node/blob/v6.7.0/lib/_stream_readable.js#L696
readableListeningis set totruebut it's never reset tofalseif allreadablelisteners are removed.Before making any changes however, I'd like to ask whether this is intended behaviour?