Skip to content

Commit ace1009

Browse files
committedMar 23, 2016
stream: emit 'pause' on nextTick
Readable.resume() schedules the resume operation onto the next tick, whereas pause() has immediate effect. This means that in a sequence stream.resume(); stream.pause(); .. the 'pause' event will be triggered before the resume operation is performed. For process.stdin, we are relying on the 'pause' event to stop reading on the underlying handle. This fix ensures that reads are started and stopped in the same order as resume() and pause() are called. PR-URL: nodejs#5776 Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
1 parent 4611389 commit ace1009

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎lib/_stream_readable.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ Readable.prototype.pause = function() {
738738
if (false !== this._readableState.flowing) {
739739
debug('pause');
740740
this._readableState.flowing = false;
741-
this.emit('pause');
741+
// Emit 'pause' on next tick as we do for 'resume'
742+
process.nextTick(() => this.emit('pause'));
742743
}
743744
return this;
744745
};

0 commit comments

Comments
 (0)
Please sign in to comment.