Permalink
Browse files

Added `Socket#bind()` "bind" event

  • Loading branch information...
1 parent 9975a15 commit 31b5ec5a878ba36f28fd3e8ac8c695185fd27127 @tj tj committed Oct 19, 2011
Showing with 28 additions and 0 deletions.
  1. +3 −0 lib/index.js
  2. +25 −0 test/test.socket.events.js
View
@@ -151,6 +151,8 @@ Object.keys(opts).forEach(function(name){
/**
* Async bind.
*
+ * Emits the "bind" event.
+ *
* @param {String} addr
* @param {Function} cb
* @return {Socket} for chaining
@@ -162,6 +164,7 @@ Socket.prototype.bind = function(addr, cb) {
self._watcher.stop();
self._zmq.bind(addr, function(err) {
self._watcher.start();
+ self.emit('bind');
cb && cb(err);
});
return this;
View
@@ -0,0 +1,25 @@
+
+var zmq = require('../')
+ , should = require('should');
+
+var rep = zmq.socket('rep')
+ , req = zmq.socket('req');
+
+rep.on('message', function(msg){
+ msg.should.be.an.instanceof(Buffer);
+ msg.toString().should.equal('hello');
+ rep.send('world');
+});
+
+rep.bind('inproc://stuff');
+
+rep.on('bind', function(){
+ req.connect('inproc://stuff');
+ req.send('hello');
+ req.on('message', function(msg){
+ msg.should.be.an.instanceof(Buffer);
+ msg.toString().should.equal('world');
+ req.close();
+ rep.close();
+ });
+});

0 comments on commit 31b5ec5

Please sign in to comment.