Skip to content

Commit

Permalink
doc: refactor signal info in child_process.md
Browse files Browse the repository at this point in the history
* Since exec calls execFile and execFile internally calls spawn with
  options.signal, the signal parameter has been documented under exec
  as well.
* Refactored the description of signal under all the functions.
* As the usage of signal has been explained using an example under
  spawn, this removes the rest of the examples as those are very
  similar.
  • Loading branch information
RaisinTen committed Feb 26, 2021
1 parent 5c3bc21 commit 8a9f442
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ changes:
* `shell` {string} Shell to execute the command with. See
[Shell requirements][] and [Default Windows shell][]. **Default:**
`'/bin/sh'` on Unix, `process.env.ComSpec` on Windows.
* `signal` {AbortSignal} allows aborting the child process using an
AbortSignal.
* `timeout` {number} **Default:** `0`
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
stderr. If exceeded, the child process is terminated and any output is
Expand Down Expand Up @@ -246,6 +248,9 @@ async function lsExample() {
lsExample();
```

The `signal` option works exactly the same way it does in
[`child_process.spawn()`][].

### `child_process.execFile(file[, args][, options][, callback])`
<!-- YAML
added: v0.1.91
Expand Down Expand Up @@ -280,7 +285,8 @@ changes:
`'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different
shell can be specified as a string. See [Shell requirements][] and
[Default Windows shell][]. **Default:** `false` (no shell).
* `signal` {AbortSignal} allows aborting the execFile using an AbortSignal.
* `signal` {AbortSignal} allows aborting the child process using an
AbortSignal.
* `callback` {Function} Called with the output when process terminates.
* `error` {Error}
* `stdout` {string|Buffer}
Expand Down Expand Up @@ -334,18 +340,8 @@ getVersion();
function. Any input containing shell metacharacters may be used to trigger
arbitrary command execution.**

If the `signal` option is enabled, calling `.abort()` on the corresponding
`AbortController` is similar to calling `.kill()` on the child process except
the error passed to the callback will be an `AbortError`:

```js
const controller = new AbortController();
const { signal } = controller;
const child = execFile('node', ['--version'], { signal }, (error) => {
console.log(error); // an AbortError
});
controller.abort();
```
The `signal` option works exactly the same way it does in
[`child_process.spawn()`][].

### `child_process.fork(modulePath[, args][, options])`
<!-- YAML
Expand Down Expand Up @@ -382,7 +378,8 @@ changes:
* `serialization` {string} Specify the kind of serialization used for sending
messages between processes. Possible values are `'json'` and `'advanced'`.
See [Advanced serialization][] for more details. **Default:** `'json'`.
* `signal` {AbortSignal} Allows closing the subprocess using an AbortSignal.
* `signal` {AbortSignal} Allows closing the child process using an
AbortSignal.
* `silent` {boolean} If `true`, stdin, stdout, and stderr of the child will be
piped to the parent, otherwise they will be inherited from the parent, see
the `'pipe'` and `'inherit'` options for [`child_process.spawn()`][]'s
Expand Down Expand Up @@ -476,7 +473,8 @@ changes:
when `shell` is specified and is CMD. **Default:** `false`.
* `windowsHide` {boolean} Hide the subprocess console window that would
normally be created on Windows systems. **Default:** `false`.
* `signal` {AbortSignal} allows aborting the execFile using an AbortSignal.
* `signal` {AbortSignal} allows aborting the child process using an
AbortSignal.

* Returns: {ChildProcess}

Expand Down

0 comments on commit 8a9f442

Please sign in to comment.