Created
October 27, 2012 21:24
-
-
Save groundwater/3966362 to your computer and use it in GitHub Desktop.
ZeroMQ Async Weirdness
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 zmq = require('zmq') | |
function sockit(name){ | |
var sock = zmq.socket('req'); | |
sock.connect('tcp://127.0.0.1:9000'); | |
sock.on('message', function(res){ | |
console.log("%s: %s",name,res.toString()) | |
}); | |
return sock; | |
} | |
sockit('one').send( JSON.stringify({timeout:5000,name:'one'}) ) | |
sockit('two').send( JSON.stringify({timeout:1000,name:'two'}) ) | |
sockit('thr').send( JSON.stringify({timeout:0,name:'thr'}) ) |
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
14:23:20 server.1 | Received: one | |
14:23:25 server.1 | Received: two | |
14:23:25 client.1 | one: one | |
14:23:26 server.1 | Received: thr |
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 zmq = require('zmq') | |
var sock = zmq.socket('rep'); | |
sock.bindSync('tcp://127.0.0.1:9000'); | |
sock.on('message', function(res){ | |
var message = JSON.parse(res) | |
console.log("Received:",message.name) | |
var timeout = message.timeout; | |
var name = message.name; | |
setTimeout(function(){ | |
sock.send(name); | |
},timeout); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment