Last active
March 7, 2020 13:18
-
-
Save memob0x/881efbfd7566c04e5e05fe5875ba2ffd to your computer and use it in GitHub Desktop.
I had to work with jQuery lately (2.x.y) and I was quite disappointed there was no Promise.allSettled-like implementation in its $.Deferred object api, so here it is...
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
const deferredsAllSettled = deferreds => { | |
const settlements = []; | |
deferreds.forEach(deferred => { | |
const settlement = jQuery.Deferred(); | |
deferred.always(settlement.resolve); | |
settlements.push(settlement); | |
}); | |
const returnedDeferred = $.Deferred(); | |
jQuery.when | |
.apply(jQuery, settlements) | |
.then(() => | |
returnedDeferred.resolve( | |
deferreds.map(deferred => deferred.promise()) | |
) | |
); | |
return returnedDeferred.promise(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment