MCPcopy Create free account
hub / github.com/nodejs/node / primary

Function primary

test/parallel/test-child-process-recv-handle.js:36–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34 primary();
35
36function primary() {
37 // spawn() can only create one IPC channel so we use stdin/stdout as an
38 // ad-hoc command channel.
39 const proc = spawn(process.execPath, [
40 '--expose-internals', __filename, 'worker',
41 ], {
42 stdio: ['pipe', 'pipe', 'pipe', 'ipc']
43 });
44 let handle = null;
45 proc.on('exit', () => {
46 handle.close();
47 });
48 proc.stdout.on('data', common.mustCall((data) => {
49 assert.strictEqual(data.toString(), 'ok\r\n');
50 net.createServer(common.mustNotCall()).listen(0, function() {
51 handle = this._handle;
52 proc.send('one');
53 proc.send('two', handle);
54 proc.send('three');
55 proc.stdin.write('ok\r\n');
56 });
57 }));
58 proc.stderr.pipe(process.stderr);
59}
60
61function worker() {
62 const { kChannelHandle } = require('internal/child_process');

Calls 7

listenMethod · 0.80
spawnFunction · 0.70
closeMethod · 0.65
sendMethod · 0.65
onMethod · 0.45
toStringMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected