mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
stream: propagate AbortSignal reason
PR-URL: https://github.com/nodejs/node/pull/55473 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
This commit is contained in:
parent
603e55d94d
commit
4a00f9a1c4
@ -203,7 +203,7 @@ function pipelineImpl(streams, callback, opts) {
|
||||
validateAbortSignal(outerSignal, 'options.signal');
|
||||
|
||||
function abort() {
|
||||
finishImpl(new AbortError());
|
||||
finishImpl(new AbortError(undefined, { cause: outerSignal?.reason }));
|
||||
}
|
||||
|
||||
addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
|
||||
|
@ -1344,12 +1344,13 @@ tmpdir.refresh();
|
||||
|
||||
{
|
||||
const ac = new AbortController();
|
||||
const reason = new Error('Reason');
|
||||
const r = Readable.from(async function* () {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await Promise.resolve();
|
||||
yield String(i);
|
||||
if (i === 5) {
|
||||
ac.abort();
|
||||
ac.abort(reason);
|
||||
}
|
||||
}
|
||||
}());
|
||||
@ -1362,6 +1363,7 @@ tmpdir.refresh();
|
||||
});
|
||||
const cb = common.mustCall((err) => {
|
||||
assert.strictEqual(err.name, 'AbortError');
|
||||
assert.strictEqual(err.cause, reason);
|
||||
assert.strictEqual(res, '012345');
|
||||
assert.strictEqual(w.destroyed, true);
|
||||
assert.strictEqual(r.destroyed, true);
|
||||
|
Loading…
Reference in New Issue
Block a user