mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00: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:
parent
b2e1a01516
commit
0d0f151a46
@ -819,7 +819,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 });
|
||||
@ -833,7 +833,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);
|
||||
}));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user