aphyr/gist:3200829
Created
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