Skip to content

Instantly share code, notes, and snippets.

@MatthaeusHarris
Created August 29, 2014 20:57
Show Gist options
  • Save MatthaeusHarris/a8a110a6d799a0be9664 to your computer and use it in GitHub Desktop.
Save MatthaeusHarris/a8a110a6d799a0be9664 to your computer and use it in GitHub Desktop.
var eventAccumulator = function(event, eventsList, queue, callback) {
// logger.log("arena","eventAccumulator(%s,%s,%s,callback)",event, JSON.stringify(eventsList), JSON.stringify(queue));
logger.log("arena","eventAccumulator queue: " + queue + " event: " + event);
if (typeof eventAccumulator[queue] === 'undefined' || typeof eventAccumulator[queue].eventList === 'undefined') {
eventAccumulator[queue] = {};
eventAccumulator[queue].eventList = [];
for (var i in eventsList) {
eventAccumulator[queue].eventList.push(eventsList[i])
}
}
eventAccumulator[queue].eventList = _.without(eventAccumulator[queue].eventList, event);
logger.log("arena","Still waiting for events: " + JSON.stringify(eventAccumulator[queue].eventList));
if (eventAccumulator[queue].eventList.length == 0) {
delete(eventAccumulator[queue]);
logger.log("arena","Calling callback for queue " + queue);
callback();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment