MCPcopy Index your code
hub / github.com/nodejs/node / parent

Function parent

test/parallel/test-child-process-stdio-big-write-end.js:41–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41function parent() {
42 const spawn = require('child_process').spawn;
43 const child = spawn(process.execPath, [__filename, 'child']);
44 let sent = 0;
45
46 let n = '';
47 child.stdout.setEncoding('ascii');
48 child.stdout.on('data', mustCallAtLeast((c) => {
49 n += c;
50 }));
51 child.stdout.on('end', mustCall(() => {
52 assert.strictEqual(+n, sent);
53 debug('ok');
54 }));
55
56 // Write until the buffer fills up.
57 let buf;
58 do {
59 bufsize += 1024;
60 buf = Buffer.alloc(bufsize, '.');
61 sent += bufsize;
62 } while (child.stdin.write(buf));
63
64 // Then write a bunch more times.
65 for (let i = 0; i < 100; i++) {
66 const buf = Buffer.alloc(bufsize, '.');
67 sent += bufsize;
68 child.stdin.write(buf);
69 }
70
71 // Now end, before it's all flushed.
72 child.stdin.end();
73
74 // now we wait...
75}
76
77function child() {
78 let received = 0;

Calls 10

mustCallAtLeastFunction · 0.85
allocMethod · 0.80
spawnFunction · 0.70
mustCallFunction · 0.70
requireFunction · 0.50
debugFunction · 0.50
setEncodingMethod · 0.45
onMethod · 0.45
writeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…