Skip to content

Commit

Permalink
stream: emit 'pause' on nextTick
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: jasnell - James M Snell <[email protected]>
  • Loading branch information
orangemocha committed Mar 23, 2016
1 parent 4611389 commit ace1009
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ Readable.prototype.pause = function() {
if (false !== this._readableState.flowing) {
debug('pause');
this._readableState.flowing = false;
this.emit('pause');
// Emit 'pause' on next tick as we do for 'resume'
process.nextTick(() => this.emit('pause'));
}
return this;
};
Expand Down

0 comments on commit ace1009

Please sign in to comment.