| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0b691ce commit 385e8e8
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -351,6 +351,9 @@ controller.abort(); | |||
| 351 | 351 | <!-- YAML | |
| 352 | 352 | added: v0.5.0 | |
| 353 | 353 | changes: | |
| 354 | + - version: REPLACEME | ||
| 355 | + pr-url: https://github.com/nodejs/node/pull/36603 | ||
| 356 | + description: AbortSignal support was added. | ||
| 354 | 357 | - version: | |
| 355 | 358 | - v13.2.0 | |
| 356 | 359 | - v12.16.0 | |
@@ -375,9 +378,11 @@ changes: | |||
| 375 | 378 | * `execPath` {string} Executable used to create the child process. | |
| 376 | 379 | * `execArgv` {string[]} List of string arguments passed to the executable. | |
| 377 | 380 | **Default:** `process.execArgv`. | |
| 381 | + * `gid` {number} Sets the group identity of the process (see setgid(2)). | ||
| 378 | 382 | * `serialization` {string} Specify the kind of serialization used for sending | |
| 379 | 383 | messages between processes. Possible values are `'json'` and `'advanced'`. | |
| 380 | 384 | See [Advanced serialization][] for more details. **Default:** `'json'`. | |
| 385 | + * `signal` {AbortSignal} Allows closing the subprocess using an AbortSignal. | ||
| 381 | 386 | * `silent` {boolean} If `true`, stdin, stdout, and stderr of the child will be | |
| 382 | 387 | piped to the parent, otherwise they will be inherited from the parent, see | |
| 383 | 388 | the `'pipe'` and `'inherit'` options for [`child_process.spawn()`][]'s | |
@@ -386,10 +391,9 @@ changes: | |||
| 386 | 391 | When this option is provided, it overrides `silent`. If the array variant | |
| 387 | 392 | is used, it must contain exactly one item with value `'ipc'` or an error | |
| 388 | 393 | will be thrown. For instance `[0, 1, 2, 'ipc']`. | |
| 394 | + * `uid` {number} Sets the user identity of the process (see setuid(2)). | ||
| 389 | 395 | * `windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is | |
| 390 | 396 | done on Windows. Ignored on Unix. **Default:** `false`. | |
| 391 | - * `uid` {number} Sets the user identity of the process (see setuid(2)). | ||
| 392 | - * `gid` {number} Sets the group identity of the process (see setgid(2)). | ||
| 393 | 397 | * Returns: {ChildProcess} | |
| 394 | 398 | ||
| 395 | 399 | The `child_process.fork()` method is a special case of | |
@@ -420,6 +424,9 @@ current process. | |||
| 420 | 424 | The `shell` option available in [`child_process.spawn()`][] is not supported by | |
| 421 | 425 | `child_process.fork()` and will be ignored if set. | |
| 422 | 426 | ||
| 427 | + The `signal` option works exactly the same way it does in | ||
| 428 | + [`child_process.spawn()`][]. | ||
| 429 | + | ||
| 423 | 430 | ### `child_process.spawn(command[, args][, options])` | |
| 424 | 431 | <!-- YAML | |
| 425 | 432 | added: v0.1.90 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,7 +127,7 @@ function fork(modulePath /* , args, options */) { | |||
| 127 | 127 | options.execPath = options.execPath || process.execPath; | |
| 128 | 128 | options.shell = false; | |
| 129 | 129 | ||
| 130 | - return spawn(options.execPath, args, options); | ||
| 130 | + return spawnWithSignal(options.execPath, args, options); | ||
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | 133 | function _forkChild(fd, serializationMode) { | |
@@ -719,7 +719,7 @@ function spawnWithSignal(file, args, options) { | |||
| 719 | 719 | validateAbortSignal(options.signal, 'options.signal'); | |
| 720 | 720 | function kill() { | |
| 721 | 721 | if (child._handle) { | |
| 722 | - child._handle.kill('SIGTERM'); | ||
| 722 | + child.kill('SIGTERM'); | ||
| 723 | 723 | child.emit('error', new AbortError()); | |
| 724 | 724 | } | |
| 725 | 725 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + setInterval(() => { | ||
| 2 | + // Starting an interval to stay alive. | ||
| 3 | + }, 1000); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + // Flags: --experimental-abortcontroller | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const { mustCall } = require('../common'); | ||
| 5 | + const { strictEqual } = require('assert'); | ||
| 6 | + const fixtures = require('../common/fixtures'); | ||
| 7 | + const { fork } = require('child_process'); | ||
| 8 | + | ||
| 9 | + { | ||
| 10 | + // Test aborting a forked child_process after calling fork | ||
| 11 | + const ac = new AbortController(); | ||
| 12 | + const { signal } = ac; | ||
| 13 | + const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { | ||
| 14 | + signal | ||
| 15 | + }); | ||
| 16 | + cp.on('exit', mustCall()); | ||
| 17 | + cp.on('error', mustCall((err) => { | ||
| 18 | + strictEqual(err.name, 'AbortError'); | ||
| 19 | + })); | ||
| 20 | + process.nextTick(() => ac.abort()); | ||
| 21 | + } | ||
| 22 | + { | ||
| 23 | + // Test passing an already aborted signal to a forked child_process | ||
| 24 | + const ac = new AbortController(); | ||
| 25 | + const { signal } = ac; | ||
| 26 | + ac.abort(); | ||
| 27 | + const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { | ||
| 28 | + signal | ||
| 29 | + }); | ||
| 30 | + cp.on('exit', mustCall()); | ||
| 31 | + cp.on('error', mustCall((err) => { | ||
| 32 | + strictEqual(err.name, 'AbortError'); | ||
| 33 | + })); | ||
| 34 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments