Created
December 18, 2020 08:59
-
-
Save maxboeck/5e505c522f925c208ab6e58d427228af to your computer and use it in GitHub Desktop.
Promise.allSettled
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
// Promise.all: if one promise rejects, all fail. | |
const [dogs, cats, possums] = await Promise.all([ | |
getDogs(), | |
getCats(), | |
getPossums() | |
]) | |
// Promise.allSettled: if one rejects, | |
// the others will still go through! | |
const allRequests = await Promise.allSettled([ | |
getDogs(), | |
getCats(), | |
getPossums() | |
]) | |
const [dogs, cats, possums] = allRequests.map((result) => | |
result.status === 'fulfilled' ? result.value : undefined | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment