Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created March 12, 2012 23:55
Show Gist options
  • Save redsquirrel/2025533 to your computer and use it in GitHub Desktop.
Save redsquirrel/2025533 to your computer and use it in GitHub Desktop.
A child sending a message to its parent.
var fork = require('child_process').fork;
if (process.argv[2] == 'son') {
setTimeout(function() {
process.send({ result: 'hi dad' });
process.exit(0);
}, 1000);
} else {
var child = fork(__filename, [ 'son' ]);
child.on('message', function(m) {
console.log(m.result)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment