mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
stream: emit 'pause' on unpipe
unpipe should use pause() instead of mutating state.flowing directly so that pausing side effects such as emitting 'pause' are properly performed. Fixes: https://github.com/nodejs/node/issues/32470 PR-URL: https://github.com/nodejs/node/pull/32476 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
deab08bc4e
commit
56da8dfd86
2 files changed
+12
-2
No files matched your search
@@ -818,7 +818,7 @@ Readable.prototype.unpipe = function(dest) {
|
||||
// remove all.
|
||||
var dests = state.pipes;
|
||||
state.pipes = [];
|
||||
state.flowing = false;
|
||||
this.pause();
|
||||
|
||||
for (const dest of dests)
|
||||
dest.emit('unpipe', this, { hasUnpiped: false });
|
||||
@@ -832,7 +832,7 @@ Readable.prototype.unpipe = function(dest) {
|
||||
|
||||
state.pipes.splice(index, 1);
|
||||
if (state.pipes.length === 0)
|
||||
state.flowing = false;
|
||||
this.pause();
|
||||
|
||||
dest.emit('unpipe', this, unpipeInfo);
|
||||
|
||||
|
||||
@@ -84,3 +84,13 @@ assert.strictEqual(source._readableState.pipes.length, 0);
|
||||
checkDestCleanup(dest2);
|
||||
source.unpipe();
|
||||
}
|
||||
|
||||
{
|
||||
const src = Readable({ read: () => {} });
|
||||
const dst = Writable({ write: () => {} });
|
||||
src.pipe(dst);
|
||||
src.on('resume', common.mustCall(() => {
|
||||
src.on('pause', common.mustCall());
|
||||
src.unpipe(dst);
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user