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

Function worker

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

Source from the content-addressed store, hash-verified

59}
60
61function worker() {
62 const { kChannelHandle } = require('internal/child_process');
63 process[kChannelHandle].readStop(); // Make messages batch up.
64 process.stdout.ref();
65 process.stdout.write('ok\r\n');
66 process.stdin.once('data', common.mustCall((data) => {
67 assert.strictEqual(data.toString(), 'ok\r\n');
68 process[kChannelHandle].readStart();
69 }));
70 let n = 0;
71 process.on('message', common.mustCall((msg, handle) => {
72 n += 1;
73 if (n === 1) {
74 assert.strictEqual(msg, 'one');
75 assert.strictEqual(handle, undefined);
76 } else if (n === 2) {
77 assert.strictEqual(msg, 'two');
78 assert.ok(handle !== null && typeof handle === 'object');
79 handle.close();
80 } else if (n === 3) {
81 assert.strictEqual(msg, 'three');
82 assert.strictEqual(handle, undefined);
83 process.exit();
84 }
85 }, 3));
86}

Calls 11

refMethod · 0.65
closeMethod · 0.65
requireFunction · 0.50
readStopMethod · 0.45
writeMethod · 0.45
onceMethod · 0.45
toStringMethod · 0.45
readStartMethod · 0.45
onMethod · 0.45
okMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected