Last active
November 23, 2017 23:05
-
-
Save dpnishant/43096af3fecde4ec9fdea7c1d81cf543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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