forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: support AbortSignal in fork
PR-URL: nodejs#36603 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
1 parent
f2cbc23
commit a531d53
Showing
4 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
setInterval(() => { | ||
// Starting an interval to stay alive. | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Flags: --experimental-abortcontroller | ||
'use strict'; | ||
|
||
const { mustCall } = require('../common'); | ||
const { strictEqual } = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
const { fork } = require('child_process'); | ||
|
||
{ | ||
// Test aborting a forked child_process after calling fork | ||
const ac = new AbortController(); | ||
const { signal } = ac; | ||
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { | ||
signal | ||
}); | ||
cp.on('exit', mustCall()); | ||
cp.on('error', mustCall((err) => { | ||
strictEqual(err.name, 'AbortError'); | ||
})); | ||
process.nextTick(() => ac.abort()); | ||
} | ||
{ | ||
// Test passing an already aborted signal to a forked child_process | ||
const ac = new AbortController(); | ||
const { signal } = ac; | ||
ac.abort(); | ||
const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { | ||
signal | ||
}); | ||
cp.on('exit', mustCall()); | ||
cp.on('error', mustCall((err) => { | ||
strictEqual(err.name, 'AbortError'); | ||
})); | ||
} |