Skip to content

Instantly share code, notes, and snippets.

@maxboeck
Created December 18, 2020 08:59
Show Gist options
  • Save maxboeck/5e505c522f925c208ab6e58d427228af to your computer and use it in GitHub Desktop.
Save maxboeck/5e505c522f925c208ab6e58d427228af to your computer and use it in GitHub Desktop.
Promise.allSettled
// 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