Created
August 7, 2018 16:59
-
-
Save natterstefan/f8bd542713b8a65256c8d887a45376f8 to your computer and use it in GitHub Desktop.
Avoiding promise.all to fail
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
// 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