Skip to content

Instantly share code, notes, and snippets.

@nlacasse
Created April 6, 2012 23:22
Show Gist options
  • Save nlacasse/2323907 to your computer and use it in GitHub Desktop.
Save nlacasse/2323907 to your computer and use it in GitHub Desktop.
task manager
TaskManager.prototype.handle = function(result) {
var emitter, emitters, task_id, tm, _results;
tm = this;
if (result.identifier) {
if ((emitters = this.matchatron.take(result))) {
_results = [];
for (task_id in emitters) {
emitter = emitters[task_id];
if (result.error) {
_results.push(emitter.emit("error", result.error, result));
} else if (result.timeout) {
_results.push(emitter.emit("timeout"));
} else {
_results.push(emitter.emit("success", result));
}
}
return _results;
} else {
return logger.debug("Received result with unmatchable identifier");
}
} else {
logger.warn("Received result with no identifier");
return logger.debug(JSON.stringify(result));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment