diff --git a/README.md b/README.md index 9e9328c..7eac581 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,8 @@ Sends a request to every nodes, that will respond through the `customHook` metho ```js // on every node -io.adapter.customHook = function (data) { - return 'hello ' + data; +io.adapter.customHook = function (data, cb) { + cb('hello ' + data); } // then diff --git a/index.js b/index.js index 991ee1d..5920217 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,7 @@ function adapter(uri, opts) { this.requestChannel = prefix + '-request#' + this.nsp.name + '#'; this.responseChannel = prefix + '-response#' + this.nsp.name + '#'; this.requests = {}; - this.customHook = function(){ return null; } + this.customHook = function(data, cb){ cb(null); } if (String.prototype.startsWith) { this.channelMatches = function (messageChannel, subscribedChannel) { @@ -275,14 +275,16 @@ function adapter(uri, opts) { break; case requestTypes.customRequest: - var data = this.customHook(request.data); + this.customHook(request.data, function(data) { - var response = JSON.stringify({ - requestid: request.requestid, - data: data + var response = JSON.stringify({ + requestid: request.requestid, + data: data + }); + + pub.publish(self.responseChannel, response); }); - pub.publish(self.responseChannel, response); break; default: diff --git a/test/index.js b/test/index.js index e7b28b3..a144f63 100644 --- a/test/index.js +++ b/test/index.js @@ -231,9 +231,9 @@ var socket1, socket2, socket3; }); it('sends a custom request', function(done){ - namespace1.adapter.customHook = function myCustomHook(data){ + namespace1.adapter.customHook = function myCustomHook(data, cb){ expect(data).to.be('hello'); - return this.uid; + cb(this.uid); } namespace3.adapter.customRequest('hello', function(err, replies){