Skip to content

Instantly share code, notes, and snippets.

@dylanvee
Created August 23, 2013 22:05
Show Gist options
  • Save dylanvee/6324492 to your computer and use it in GitHub Desktop.
Save dylanvee/6324492 to your computer and use it in GitHub Desktop.
// promises is an array of jqXHRs or what have you
var deferreds = _.map(promises, function(promise) {
var deferred = $.Deferred();
promise.then(
function() {
deferred.resolve(true);
},
function() {
deferred.resolve(false);
}
);
return deferred;
});
$.when.apply($, deferreds).done(function() {
var results = _.countBy(arguments),
numSuccesses = results["true"] || 0,
numFailures = results["false"] || 0;
console.log(numSuccesses + " operations succeeded");
console.log(numFailures + " operations failed");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment