1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cp = require('child_process'); 5const NUM_MESSAGES = 10; 6const values = []; 7 8for (let i = 0; i < NUM_MESSAGES; ++i) { 9 values[i] = i; 10} 11 12if (process.argv[2] === 'child') { 13 const received = values.map(() => { return false; }); 14 15 process.on('uncaughtException', common.mustCall((err) => { 16 received[err] = true; 17 const done = received.every((element) => { return element === true; }); 18 19 if (done) 20 process.disconnect(); 21 }, NUM_MESSAGES)); 22 23 process.on('message', (msg) => { 24 // If messages are handled synchronously, throwing should break the IPC 25 // message processing. 26 throw msg; 27 }); 28 29 process.send('ready'); 30} else { 31 const child = cp.fork(__filename, ['child']); 32 33 child.on('message', common.mustCall((msg) => { 34 assert.strictEqual(msg, 'ready'); 35 values.forEach((value) => { 36 child.send(value); 37 }); 38 })); 39} 40