Created
July 29, 2012 18:29
-
-
Save aphyr/3200829 to your computer and use it in GitHub Desktop.
Node.js message passing test
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
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