Skip to content

Commit 906fd31

Browse files
committed
fixup: compat paused
1 parent 2a27826 commit 906fd31

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

lib/_stream_readable.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const {
2828
ObjectDefineProperty,
2929
ObjectSetPrototypeOf,
3030
SymbolAsyncIterator,
31+
Symbol
3132
} = primordials;
3233

3334
module.exports = Readable;
@@ -51,6 +52,8 @@ const {
5152
ERR_STREAM_UNSHIFT_AFTER_END_EVENT
5253
} = require('internal/errors').codes;
5354

55+
const kPaused = Symbol('kPaused');
56+
5457
// Lazy loaded to improve the startup performance.
5558
let StringDecoder;
5659
let createReadableStreamAsyncIterator;
@@ -126,7 +129,7 @@ function ReadableState(options, stream, isDuplex) {
126129
this.emittedReadable = false;
127130
this.readableListening = false;
128131
this.resumeScheduled = false;
129-
this.paused = null;
132+
this[kPaused] = null;
130133

131134
// True if the error was already emitted and should not be thrown again
132135
this.errorEmitted = false;
@@ -173,6 +176,16 @@ ObjectDefineProperty(ReadableState.prototype, 'pipesCount', {
173176
}
174177
});
175178

179+
// Legacy property for `paused`
180+
ObjectDefineProperty(ReadableState.prototype, 'paused', {
181+
get() {
182+
return this[kPaused] !== false;
183+
},
184+
set(value) {
185+
this[kPaused] = Boolean(value);
186+
}
187+
});
188+
176189
function Readable(options) {
177190
if (!(this instanceof Readable))
178191
return new Readable(options);
@@ -368,7 +381,7 @@ function chunkInvalid(state, chunk) {
368381

369382

370383
Readable.prototype.isPaused = function() {
371-
return this._readableState.paused === true;
384+
return this._readableState[kPaused] === true;
372385
};
373386

374387
// Backwards compatibility.
@@ -967,7 +980,7 @@ function updateReadableListening(self) {
967980
const state = self._readableState;
968981
state.readableListening = self.listenerCount('readable') > 0;
969982

970-
if (state.resumeScheduled && state.paused === false) {
983+
if (state.resumeScheduled && state[kPaused] === false) {
971984
// Flowing needs to be set to true now, otherwise
972985
// the upcoming resume will not flow.
973986
state.flowing = true;
@@ -997,7 +1010,7 @@ Readable.prototype.resume = function() {
9971010
state.flowing = !state.readableListening;
9981011
resume(this, state);
9991012
}
1000-
state.paused = false;
1013+
state[kPaused] = false;
10011014
return this;
10021015
};
10031016

@@ -1028,7 +1041,7 @@ Readable.prototype.pause = function() {
10281041
this._readableState.flowing = false;
10291042
this.emit('pause');
10301043
}
1031-
this._readableState.paused = true;
1044+
this._readableState[kPaused] = true;
10321045
return this;
10331046
};
10341047

test/parallel/test-stream-readable-pause-and-resume.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ function readAndPause() {
5353
readable.pause();
5454

5555
process.nextTick(function() {
56-
assert(readable.isPaused()); // Throws.
56+
assert(readable.isPaused());
5757
});
5858
}

0 commit comments

Comments
 (0)