-
Notifications
You must be signed in to change notification settings - Fork 30k
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>
- Loading branch information
1 parent
256bf9e
commit 9086338
Showing
2 changed files
with
49 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)); | ||
} |