mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
stream: make Duplex inherit destroy from Writable
Make `Duplex` inherit the `destroy` method from `Writable` instead of `Readable` so that pending write callbacks are correctly invoked when the stream is destroyed. PR-URL: https://github.com/nodejs/node/pull/52318 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
461d9d665d
commit
c02de658a1
2 files changed
+17
No files matched your search
@@ -59,6 +59,9 @@ ObjectSetPrototypeOf(Duplex, Readable);
|
||||
}
|
||||
}
|
||||
|
||||
// Use the `destroy` method of `Writable`.
|
||||
Duplex.prototype.destroy = Writable.prototype.destroy;
|
||||
|
||||
function Duplex(options) {
|
||||
if (!(this instanceof Duplex))
|
||||
return new Duplex(options);
|
||||
|
||||
@@ -238,6 +238,7 @@ const assert = require('assert');
|
||||
});
|
||||
duplex.on('close', common.mustCall());
|
||||
}
|
||||
|
||||
{
|
||||
// Check abort signal
|
||||
const controller = new AbortController();
|
||||
@@ -255,3 +256,16 @@ const assert = require('assert');
|
||||
duplex.on('close', common.mustCall());
|
||||
controller.abort();
|
||||
}
|
||||
|
||||
{
|
||||
const duplex = new Duplex({
|
||||
read() {},
|
||||
write(chunk, enc, cb) { cb(); }
|
||||
});
|
||||
|
||||
duplex.cork();
|
||||
duplex.write('foo', common.mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
|
||||
}));
|
||||
duplex.destroy();
|
||||
}
|
||||
Reference in new issue
Block a user