From ace1009456380251f75c7151236064d3a7476f5b Mon Sep 17 00:00:00 2001 From: Alexis Campailla Date: Fri, 18 Mar 2016 02:05:20 +0100 Subject: [PATCH] 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 Reviewed-By: jasnell - James M Snell --- lib/_stream_readable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 338bf2a7539bfc..2ee59b4286496d 100644 --- a/lib/_stream_readable.js +++ b/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; };