Skip to content

Instantly share code, notes, and snippets.

@dpnishant
Last active November 23, 2017 23:05
Show Gist options
  • Save dpnishant/43096af3fecde4ec9fdea7c1d81cf543 to your computer and use it in GitHub Desktop.
Save dpnishant/43096af3fecde4ec9fdea7c1d81cf543 to your computer and use it in GitHub Desktop.
var sleep = require('sleep').sleep;
process.on('message', function (message) {
console.log('message from parent:', message);
});
if (process.send) {
for (let i=0, len = 100; i < len; i++) {
sleep(1);
process.send(`Hello-${i}`);
}
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9999
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}",
"port": 9999
}
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/parent.js"
}
]
}
cProcess = require('child_process');
path = require('path');
const program = path.resolve('child.js');
// const parameters = ['--inspect=9999'];
const parameters = [];
const options = {
execArgv: ['--inspect=9999'],
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
};
const child = cProcess.fork(program, parameters, options);
child.on('message', function (message) {
child.send(`Hi-${message.split('-')[1]}`);
console.log('message from child:', message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment