Browse Source

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>
process-exit-stdio-flushing
Alexis Campailla 9 years ago
parent
commit
ace1009456
  1. 3
      lib/_stream_readable.js

3
lib/_stream_readable.js

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

Loading…
Cancel
Save