Created
May 26, 2019 13:05
-
-
Save jkasaudhan/76c5038cc06398d2862174c2813eaafb to your computer and use it in GitHub Desktop.
Promise.allSetteled() feature in js
This file contains hidden or 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
// Filter out successfull i.e fulfilled or resolved promises | |
const promises = [ fetch('index.html'), fetch('https://does-not-exist/') ]; | |
const results = await Promise.allSettled(promises); | |
const successfulPromises = results.filter(p => p.status === 'fulfilled'); | |
// Filter out failed promises | |
const promises = [ fetch('index.html'), fetch('https://does-not-exist/') ]; | |
const results = await Promise.allSettled(promises); | |
const errors = results.filter(p => p.status === 'rejected') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment