Skip to content

Commit

Permalink
Implement handleOrProxyAll
Browse files Browse the repository at this point in the history
Takes a request with multiple keys and fans it out to all the
destinations responsible
  • Loading branch information
markyen committed Feb 3, 2015
1 parent 6ef6de4 commit 176fe6c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var _ = require('underscore');
var EventEmitter = require('events').EventEmitter;
var fs = require('fs');
var hammock = require('uber-hammock');
var metrics = require('metrics');
var TypedError = require('error/typed');

Expand Down Expand Up @@ -841,6 +842,37 @@ RingPop.prototype.handleOrProxy =
}
};

RingPop.prototype.handleOrProxyAll =
function handleOrProxyAll(opts) {
var self = this;
var keys = opts.keys;
var req = opts.req;
var localHandler = opts.localHandler;

var reses = {};
var dests = mapUniq(keys, this.lookup.bind(this));
dests.forEach(function(dest) {
var res = hammock.Response();
if (self.whoami() === dest) {
process.nextTick(localHandler.bind(null, req, res));
} else {
process.nextTick(self.proxyReq.bind(self, _.defaults({
dest: dest,
res: res
}, opts)));
}
reses[dest] = res;
});
return reses;

function mapUniq(list, iteratee) {
return Object.keys(list.reduce(function(acc, val) {
acc[iteratee(val)] = null;
return acc;
}, {}));
}
};

RingPop.prototype.validateProps = function validateProps(opts, props) {
for (var i = 0; i < props.length; i++) {
var prop = props[i];
Expand Down

0 comments on commit 176fe6c

Please sign in to comment.