Skip to content

Instantly share code, notes, and snippets.

@horiajurcut
Last active December 27, 2015 05:49
Show Gist options
  • Save horiajurcut/7277536 to your computer and use it in GitHub Desktop.
Save horiajurcut/7277536 to your computer and use it in GitHub Desktop.
// Extending jQuery.when
if (jQuery.when.all === undefined) {
jQuery.when.all = function(deferreds) {
var deferred = new jQuery.Deferred();
$.when.apply(jQuery, deferreds).then(
function() {
deferred.resolve(Array.prototype.slice.call(arguments));
},
function() {
deferred.fail(Array.prototype.slice.call(arguments));
}
);
return deferred;
}
}
@stodge
Copy link

stodge commented Apr 13, 2015

What happens if one or more requests fail? Do you get a fail for those that failed and resolve callbacks when the successful ones complete? I guess I'm asking if you get the complete picture. I have a situation where I need to make multiple requests but I need to know if any fail and I also need to know when ALL requests have completed (either succeeded or failed). Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment