stream: do not emit readable if the stream ended
Fixes a regression introduced by the once-per-microtick 'readable' event emission. See: https://github.com/nodejs/node/pull/17979 PR-URL: https://github.com/nodejs/node/pull/18372 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
742ae6141c
commit
0778f79cb3
@ -520,7 +520,9 @@ function emitReadable(stream) {
|
||||
function emitReadable_(stream) {
|
||||
var state = stream._readableState;
|
||||
debug('emit readable');
|
||||
stream.emit('readable');
|
||||
if (!state.destroyed && (state.length || state.ended)) {
|
||||
stream.emit('readable');
|
||||
}
|
||||
state.needReadable = !state.flowing && !state.ended;
|
||||
flow(stream);
|
||||
}
|
||||
|
39
test/parallel/test-stream-readable-no-unneeded-readable.js
Normal file
39
test/parallel/test-stream-readable-no-unneeded-readable.js
Normal file
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const { Readable, PassThrough } = require('stream');
|
||||
|
||||
const source = new Readable({
|
||||
read: () => {}
|
||||
});
|
||||
|
||||
source.push('foo');
|
||||
source.push('bar');
|
||||
source.push(null);
|
||||
|
||||
const pt = source.pipe(new PassThrough());
|
||||
|
||||
const wrapper = new Readable({
|
||||
read: () => {
|
||||
let data = pt.read();
|
||||
|
||||
if (data) {
|
||||
wrapper.push(data);
|
||||
return;
|
||||
}
|
||||
|
||||
pt.once('readable', function() {
|
||||
data = pt.read();
|
||||
if (data) {
|
||||
wrapper.push(data);
|
||||
}
|
||||
// else the end event should fire
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
pt.once('end', function() {
|
||||
wrapper.push(null);
|
||||
});
|
||||
|
||||
wrapper.resume();
|
||||
wrapper.once('end', common.mustCall());
|
Loading…
x
Reference in New Issue
Block a user