mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
stream: noop pause/resume on destroyed streams
Signed-off-by: Robert Nagy <ronagy@icloud.com> PR-URL: https://github.com/nodejs/node/pull/62557 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
This commit is contained in:
1 parent
f1ed8d63b5
commit
4dc18ef29d
2 files changed
+16
No files matched your search
@@ -1242,6 +1242,9 @@ function nReadingNextTick(self) {
|
||||
// If the user uses them, then switch into old mode.
|
||||
Readable.prototype.resume = function() {
|
||||
const state = this._readableState;
|
||||
if ((state[kState] & kDestroyed) !== 0) {
|
||||
return this;
|
||||
}
|
||||
if ((state[kState] & kFlowing) === 0) {
|
||||
debug('resume');
|
||||
// We flow only if there is no one listening
|
||||
@@ -1282,6 +1285,9 @@ function resume_(stream, state) {
|
||||
|
||||
Readable.prototype.pause = function() {
|
||||
const state = this._readableState;
|
||||
if ((state[kState] & kDestroyed) !== 0) {
|
||||
return this;
|
||||
}
|
||||
debug('call pause');
|
||||
if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) {
|
||||
debug('pause');
|
||||
|
||||
@@ -118,3 +118,13 @@ const http = require('http');
|
||||
req.end('asd');
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
// resume() and pause() should be no-ops on destroyed streams.
|
||||
const r = new Readable({ read() {} });
|
||||
r.destroy();
|
||||
r.on('resume', common.mustNotCall());
|
||||
r.on('pause', common.mustNotCall());
|
||||
r.resume();
|
||||
r.pause();
|
||||
}
|
||||
Reference in new issue
Block a user