Skip to content

Instantly share code, notes, and snippets.

@jkasaudhan
Created May 26, 2019 13:05
Show Gist options
  • Save jkasaudhan/76c5038cc06398d2862174c2813eaafb to your computer and use it in GitHub Desktop.
Save jkasaudhan/76c5038cc06398d2862174c2813eaafb to your computer and use it in GitHub Desktop.
Promise.allSetteled() feature in js
// 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