Skip to content
Myr

cancel.js

This file

Path

lib/terminate/cancel.js

25 lines · 1.1 KiB · JavaScript

Last changed by

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

History of this file

Take it

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

line 1why, one step back
1import {onAbortedSignal, validateAbortSignal} from '../utils/abort-signal.js';

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

lines 2–4why, one step back
2
3// Validate the `cancelSignal` option4export const validateCancelSignal = ({cancelSignal}) => {

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

line 5why, one step back
5 validateAbortSignal(cancelSignal, 'cancelSignal');

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

lines 6–7why, one step back
6};
7

Fix the "signal" option being silently ignored by synchronous methodsSindre Sorhusbefore adoption59de065

lines 8–14why, one step back
8// The `signal` option was renamed to `cancelSignal`. Validated for every method, otherwise synchronous methods would silently ignore it, since `child_process.spawnSync()` does not support that option either.
9export const validateRenamedSignalOption = ({signal}) => {10 if (signal !== undefined) {11 throw new TypeError('The "signal" option has been renamed to "cancelSignal" instead.');12 }13};14

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 15why, one step back
15// Terminate the subprocess when aborting the `cancelSignal` option and `gracefulSignal` is `false`

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 16why, one step back
16export const throwOnCancel = ({kill, cancelSignal, gracefulCancel, context, controller}) => cancelSignal === undefined || gracefulCancel

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

line 17why, one step back
17 ? []

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 18why, one step back
18 : [terminateOnCancel(kill, cancelSignal, context, controller)];

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

line 19why, one step back
19

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 20why, one step back
20const terminateOnCancel = async (kill, cancelSignal, context, {signal}) => {

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

line 21why, one step back
21 await onAbortedSignal(cancelSignal, signal);

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 22why, one step back
22 context.terminationReason ??= 'cancel';

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 23why, one step back
23 kill();

Improve `cancelSignal` option (#1108)ehmickybefore adoption3b56977

lines 24–25why, one step back
24 throw cancelSignal.reason;
25};