Created
August 23, 2013 22:05
-
-
Save dylanvee/6324492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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