summaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 2a2122e0e5..47dbae31b5 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -114,6 +114,7 @@ function ReadableState(options, stream, isDuplex) {
this.emittedReadable = false;
this.readableListening = false;
this.resumeScheduled = false;
+ this.paused = true;
// Should close be emitted on destroy. Defaults to true.
this.emitClose = options.emitClose !== false;
@@ -862,10 +863,16 @@ Readable.prototype.removeAllListeners = function(ev) {
};
function updateReadableListening(self) {
- self._readableState.readableListening = self.listenerCount('readable') > 0;
+ const state = self._readableState;
+ state.readableListening = self.listenerCount('readable') > 0;
- // crude way to check if we should resume
- if (self.listenerCount('data') > 0) {
+ if (state.resumeScheduled && !state.paused) {
+ // flowing needs to be set to true now, otherwise
+ // the upcoming resume will not flow.
+ state.flowing = true;
+
+ // crude way to check if we should resume
+ } else if (self.listenerCount('data') > 0) {
self.resume();
}
}
@@ -887,6 +894,7 @@ Readable.prototype.resume = function() {
state.flowing = !state.readableListening;
resume(this, state);
}
+ state.paused = false;
return this;
};
@@ -917,6 +925,7 @@ Readable.prototype.pause = function() {
this._readableState.flowing = false;
this.emit('pause');
}
+ this._readableState.paused = true;
return this;
};