@@ -280,7 +280,7 @@ changes: |
280 | 280 | `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different |
281 | 281 | shell can be specified as a string. See [Shell requirements][] and |
282 | 282 | [Default Windows shell][]. **Default:** `false` (no shell). |
283 | | - * `signal` {AbortSignal} allows aborting the execFile using an AbortSignal |
| 283 | + * `signal` {AbortSignal} allows aborting the execFile using an AbortSignal. |
284 | 284 | * `callback` {Function} Called with the output when process terminates. |
285 | 285 | * `error` {Error} |
286 | 286 | * `stdout` {string|Buffer} |
@@ -344,7 +344,7 @@ const { signal } = controller; |
344 | 344 | const child = execFile('node', ['--version'], { signal }, (error) => { |
345 | 345 | console.log(error); // an AbortError |
346 | 346 | }); |
347 | | -signal.abort(); |
| 347 | +controller.abort(); |
348 | 348 | ``` |
349 | 349 |
|
350 | 350 | ### `child_process.fork(modulePath[, args][, options])` |
@@ -424,6 +424,9 @@ The `shell` option available in [`child_process.spawn()`][] is not supported by |
424 | 424 | <!-- YAML |
425 | 425 | added: v0.1.90 |
426 | 426 | changes: |
| 427 | + - version: REPLACEME |
| 428 | + pr-url: https://github.com/nodejs/node/pull/36432 |
| 429 | + description: AbortSignal support was added. |
427 | 430 | - version: |
428 | 431 | - v13.2.0 |
429 | 432 | - v12.16.0 |
@@ -466,6 +469,8 @@ changes: |
466 | 469 | when `shell` is specified and is CMD. **Default:** `false`. |
467 | 470 | * `windowsHide` {boolean} Hide the subprocess console window that would |
468 | 471 | normally be created on Windows systems. **Default:** `false`. |
| 472 | + * `signal` {AbortSignal} allows aborting the execFile using an AbortSignal. |
| 473 | + |
469 | 474 | * Returns: {ChildProcess} |
470 | 475 |
|
471 | 476 | The `child_process.spawn()` method spawns a new process using the given |
@@ -572,6 +577,20 @@ Node.js currently overwrites `argv[0]` with `process.execPath` on startup, so |
572 | 577 | parameter passed to `spawn` from the parent, retrieve it with the |
573 | 578 | `process.argv0` property instead. |
574 | 579 |
|
| 580 | +If the `signal` option is enabled, calling `.abort()` on the corresponding |
| 581 | +`AbortController` is similar to calling `.kill()` on the child process except |
| 582 | +the error passed to the callback will be an `AbortError`: |
| 583 | + |
| 584 | +```js |
| 585 | +const controller = new AbortController(); |
| 586 | +const { signal } = controller; |
| 587 | +const grep = spawn('grep', ['ssh'], { signal }); |
| 588 | +grep.on('error', (err) => { |
| 589 | + // This will be called with err being an AbortError if the controller aborts |
| 590 | +}); |
| 591 | +controller.abort(); // stops the process |
| 592 | +``` |
| 593 | + |
575 | 594 | #### `options.detached` |
576 | 595 | <!-- YAML |
577 | 596 | added: v0.7.10 |
|