-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: queue pending messages
It fixes the problem of the child process not receiving messages. Fixes: #41134 PR-URL: #41221 Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Backport-PR-URL: #42840
- Loading branch information
1 parent
c73ac52
commit 4203d13
Showing
2 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import '../common/index.mjs'; | ||
import assert from 'assert'; | ||
import { fork } from 'child_process'; | ||
import { once } from 'events'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
if (process.argv[2] !== 'child') { | ||
const filename = fileURLToPath(import.meta.url); | ||
const cp = fork(filename, ['child']); | ||
const message = 'Hello World'; | ||
cp.send(message); | ||
|
||
const [received] = await once(cp, 'message'); | ||
assert.deepStrictEqual(received, message); | ||
|
||
cp.disconnect(); | ||
await once(cp, 'exit'); | ||
} else { | ||
process.on('message', (msg) => process.send(msg)); | ||
} |