Last active
September 9, 2018 17:48
-
-
Save csantos42/71a3aa8922679d35e9d5edd7d75aa9ac to your computer and use it in GitHub Desktop.
Child Process Example
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
// parent.js | |
const cp = require('child_process'); | |
const CHILD_PATH = `${__dirname}/child.js`; | |
const queue = [1, 2, 3, 4, 5]; | |
queue.forEach((num) => { | |
const child = cp.fork(CHILD_PATH); | |
child.on('message', (msg) => console.log(msg)); | |
child.send(num); | |
}); | |
// child.js | |
process.on('message', (num) => { | |
process.send(num + 1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment