Skip to content

Instantly share code, notes, and snippets.

@csantos42
Last active September 9, 2018 17:48
Show Gist options
  • Save csantos42/71a3aa8922679d35e9d5edd7d75aa9ac to your computer and use it in GitHub Desktop.
Save csantos42/71a3aa8922679d35e9d5edd7d75aa9ac to your computer and use it in GitHub Desktop.
Child Process Example
// 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