Created
November 14, 2012 15:39
-
-
Save jig/4072837 to your computer and use it in GitHub Desktop.
dnode chain workers sample
This file contains hidden or 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 dnode = require('dnode'); | |
var main = function (remote) { | |
remote.sumaQuadratica(4, 3, function (res) { | |
console.log(res); | |
worker1.end(); | |
} | |
); | |
} | |
var worker1 = dnode.connect(5001); | |
worker1.on('remote', main); |
This file contains hidden or 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 dnode = require('dnode'); | |
var main = function(remote) { | |
var worker1 = dnode( | |
{ | |
sumaQuadratica : function (a, b, callback) { | |
console.log(a, b); | |
var args = a * a + b * b; | |
remote.sqrt(args, callback); | |
} | |
} | |
); | |
worker1.listen(5001); | |
} | |
var worker2 = dnode.connect(5002); | |
worker2.on('remote', main); |
This file contains hidden or 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 dnode = require('dnode'); | |
var worker2 = dnode({ | |
sqrt : function (arg, callback) { | |
console.log(arg); | |
callback(Math.sqrt(arg)); | |
} | |
}); | |
worker2.listen(5002); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Start worker2, then worker1 and finally client.
client will send a request to worker1 who will partially solve the function and partly will delegate to worker2. After that, worker2 will return control to client by callback.
Remote callback resolution by dnode. So you need to:
{{npm install dnode}}