summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexis Campailla <alexis@janeasystems.com>2016-03-18 02:05:20 +0100
committerAlexis Campailla <alexis@janeasystems.com>2016-03-23 20:57:14 +0100
commitace1009456380251f75c7151236064d3a7476f5b (patch)
treebaa404d4ad57b2f6550d797ad776f712ff82f941 /lib
parent461138929498f31bd35bea61aa4375a2f56cceb7 (diff)
downloadandroid-node-v8-ace1009456380251f75c7151236064d3a7476f5b.tar.gz
android-node-v8-ace1009456380251f75c7151236064d3a7476f5b.tar.bz2
android-node-v8-ace1009456380251f75c7151236064d3a7476f5b.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/_stream_readable.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 338bf2a753..2ee59b4286 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;
};