Skip to content

Instantly share code, notes, and snippets.

@aphyr
Created July 29, 2012 18:29
Show Gist options
  • Save aphyr/3200829 to your computer and use it in GitHub Desktop.
Save aphyr/3200829 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