Skip to content

Commit 4a31b6f

Browse files
committed
doc: refactor signal info in child_process.md
* 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.
1 parent 9f56bc8 commit 4a31b6f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

doc/api/child_process.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ changes:
160160
* `shell` {string} Shell to execute the command with. See
161161
[Shell requirements][] and [Default Windows shell][]. **Default:**
162162
`'/bin/sh'` on Unix, `process.env.ComSpec` on Windows.
163+
* `signal` {AbortSignal} allows aborting the child process using an
164+
AbortSignal.
163165
* `timeout` {number} **Default:** `0`
164166
* `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or
165167
stderr. If exceeded, the child process is terminated and any output is
@@ -246,6 +248,9 @@ async function lsExample() {
246248
lsExample();
247249
```
248250

251+
The `signal` option works exactly the same way it does in
252+
[`child_process.spawn()`][].
253+
249254
### `child_process.execFile(file[, args][, options][, callback])`
250255
<!-- YAML
251256
added: v0.1.91
@@ -280,7 +285,8 @@ changes:
280285
`'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different
281286
shell can be specified as a string. See [Shell requirements][] and
282287
[Default Windows shell][]. **Default:** `false` (no shell).
283-
* `signal` {AbortSignal} allows aborting the execFile using an AbortSignal.
288+
* `signal` {AbortSignal} allows aborting the child process using an
289+
AbortSignal.
284290
* `callback` {Function} Called with the output when process terminates.
285291
* `error` {Error}
286292
* `stdout` {string|Buffer}
@@ -334,18 +340,8 @@ getVersion();
334340
function. Any input containing shell metacharacters may be used to trigger
335341
arbitrary command execution.**
336342

337-
If the `signal` option is enabled, calling `.abort()` on the corresponding
338-
`AbortController` is similar to calling `.kill()` on the child process except
339-
the error passed to the callback will be an `AbortError`:
340-
341-
```js
342-
const controller = new AbortController();
343-
const { signal } = controller;
344-
const child = execFile('node', ['--version'], { signal }, (error) => {
345-
console.log(error); // an AbortError
346-
});
347-
controller.abort();
348-
```
343+
The `signal` option works exactly the same way it does in
344+
[`child_process.spawn()`][].
349345

350346
### `child_process.fork(modulePath[, args][, options])`
351347
<!-- YAML
@@ -385,7 +381,8 @@ changes:
385381
* `serialization` {string} Specify the kind of serialization used for sending
386382
messages between processes. Possible values are `'json'` and `'advanced'`.
387383
See [Advanced serialization][] for more details. **Default:** `'json'`.
388-
* `signal` {AbortSignal} Allows closing the subprocess using an AbortSignal.
384+
* `signal` {AbortSignal} Allows closing the child process using an
385+
AbortSignal.
389386
* `killSignal` {string} The signal value to be used when the spawned
390387
process will be killed by the abort signal. **Default:** `'SIGTERM'`.
391388
* `silent` {boolean} If `true`, stdin, stdout, and stderr of the child will be
@@ -484,7 +481,8 @@ changes:
484481
when `shell` is specified and is CMD. **Default:** `false`.
485482
* `windowsHide` {boolean} Hide the subprocess console window that would
486483
normally be created on Windows systems. **Default:** `false`.
487-
* `signal` {AbortSignal} allows aborting the execFile using an AbortSignal.
484+
* `signal` {AbortSignal} allows aborting the child process using an
485+
AbortSignal.
488486
* `killSignal` {string} The signal value to be used when the spawned
489487
process will be killed by the abort signal. **Default:** `'SIGTERM'`.
490488

0 commit comments

Comments
 (0)