Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: make Duplex inherit destroy from Writable #52318

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/internal/streams/duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-stream-duplex-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const assert = require('assert');
});
duplex.on('close', common.mustCall());
}

{
// Check abort signal
const controller = new AbortController();
Expand All @@ -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();
}