Skip to content

Instantly share code, notes, and snippets.

@natterstefan
Created August 7, 2018 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natterstefan/f8bd542713b8a65256c8d887a45376f8 to your computer and use it in GitHub Desktop.
Save natterstefan/f8bd542713b8a65256c8d887a45376f8 to your computer and use it in GitHub Desktop.
Avoiding promise.all to fail
// inspired by (Credits):
// - A: https://davidwalsh.name/promises-results
// - B: https://nmaggioni.xyz/2016/10/13/Avoiding-Promise-all-fail-fast-behavior/
// Solution A
await Promise.all(loadDataRequests.map(p => p.catch(() => undefined)))
// Solution B
await Promise.all(
loadDataRequests.map(p =>
p.then(result => ({ result, success: true })).catch(error => ({ error, success: false })),
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment