Skip to content

Commit

Permalink
stream: defer readable and flow when sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Feb 5, 2018
1 parent 591a1c5 commit a83008a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/_stream_readable.js
Expand Up @@ -486,11 +486,18 @@ function onEofChunk(stream, state) {
}
state.ended = true;

// emit 'readable' now to make sure it gets picked up.
state.needReadable = false;
if (!state.emittedReadable) {
state.emittedReadable = true;
emitReadable_(stream);
if (state.sync && state.length) {
// if we are sync and have data in the buffer, wait until next tick
// to emit the data. otherwise we risk emitting data in the flow()
// the readable code triggers during a read() call
emitReadable(stream);
} else {
// emit 'readable' now to make sure it gets picked up.
state.needReadable = false;
if (!state.emittedReadable) {
state.emittedReadable = true;
emitReadable_(stream);
}
}
}

Expand Down

0 comments on commit a83008a

Please sign in to comment.