Skip to content

Instantly share code, notes, and snippets.

@janewang
Forked from aphyr/gist:3200829
Created August 9, 2012 21:28
Show Gist options
  • Save janewang/3308203 to your computer and use it in GitHub Desktop.
Save janewang/3308203 to your computer and use it in GitHub Desktop.
Node.js message passing test
var cluster = require('cluster');
var m = 10000000;
function bounce(msg, out) {
if (msg < m) {
out.send(msg + 1);
return null;
} else {
console.log("Finished with", msg);
out.disconnect();
return msg;
}
}
if(cluster.isMaster) {
var worker = cluster.fork();
worker.on('message', function(msg) {
bounce(msg, worker);
});
worker.send(1);
} else {
process.on('message', function(msg) {
bounce(msg, process);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment