Skip to content

Commit

Permalink
Remove localHandler in favor of emitting an event
Browse files Browse the repository at this point in the history
  • Loading branch information
markyen committed Feb 16, 2015
1 parent b1bb32a commit 1280532
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ RingPop.prototype.handleOrProxyAll =
var self = this;
var keys = opts.keys;
var req = opts.req;
var localHandler = opts.localHandler;

var whoami = this.whoami();
var keysByDest = _.groupBy(keys, this.lookup, this);
Expand All @@ -814,17 +813,16 @@ RingPop.prototype.handleOrProxyAll =
}

dests.forEach(function(dest) {
var res = hammock.Response();
res.on('response', function(err, response) {
onResponse(err, response, dest);
var res = hammock.Response(function(err, resp) {
onResponse(err, resp, dest);
});
if (whoami === dest) {
self.logger.trace('handleOrProxyAll was handled', {
keys: keys,
url: req && req.url,
dest: dest
});
localHandler(req, res);
self.emit('request', req, res);
} else {
self.logger.trace('handleOrProxyAll was proxied', {
keys: keys,
Expand All @@ -840,9 +838,9 @@ RingPop.prototype.handleOrProxyAll =
}
});

function onResponse(err, response, dest) {
function onResponse(err, resp, dest) {
responses.push({
res: response,
res: resp,
dest: dest,
keys: keysByDest[dest]
});
Expand Down
3 changes: 1 addition & 2 deletions test/integration/handle_or_proxy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('handleOrProxy() proxies for not me', function t(assert) {
});
});

test('handleOrProxyAll() proxies and calls local handler', function t(assert) {
test('handleOrProxyAll() proxies and handles locally', function t(assert) {
var handlerCallCounts = {};
var cluster = allocCluster({
createHandler: createServerHandler
Expand All @@ -69,7 +69,6 @@ test('handleOrProxyAll() proxies and calls local handler', function t(assert) {
cluster.requestAll({
keys: keys,
host: 'one',
localHandler: createServerHandler('one'),
json: { hello: true }
}, onResponses);
});
Expand Down

0 comments on commit 1280532

Please sign in to comment.