Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make customHook async #181

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down