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: https://github.com/nodejs/node/pull/5776
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
This commit is contained in:
Alexis Campailla 2016-03-18 02:05:20 +01:00
parent 4611389294
commit ace1009456

View File

@ -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;
};