node/test/es-module/test-esm-child-process-fork-main.mjs
Erick Wendel de12141dd0 child_process: queue pending messages
It fixes the problem of the child process not receiving messages.

Fixes: https://github.com/nodejs/node/issues/41134

PR-URL: https://github.com/nodejs/node/pull/41221
Reviewed-By: Adrian Estrada <edsadr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2021-12-30 05:59:49 -08:00

21 lines
549 B
JavaScript

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));
}