DEV Community

Promise.all (ES2015) vs Promise.allSettled (ES2020). What's changed? 🤔

Shahzaib Khalid on August 25, 2019

Hey! 👋 Check out today's ⚡️ Dev Tip 💡 👇 Follow me on Twitter @shahzaibkhalid for more Dev Tips! ✨ Let’s say we want to run many promises to ex...
Collapse
 
dean profile image
dean • Edited

I feel like for consistency, it should be status: 'resolved' rather than status: 'fulfilled'. Otherwise, that's pretty neat!

The concept is great, but some renaming I think would be nice. I think the most important renaming should be status: 'resolved' rather than 'fulfilled', and perhaps renaming Promise.allSettled to something else... Not quite sure yet.

Collapse
 
shahzaibkhalid profile image
Shahzaib Khalid

Dean, the specification uses the following naming convention:

  • fulfilled - The action relating to the promise succeeded
  • rejected - The action relating to the promise failed
  • pending - Hasn't fulfilled or rejected yet
  • settled - Has fulfilled or rejected
Collapse
 
dean profile image
dean

Just looked this up on MDN, didn't know that this was the current specification! Thanks for letting me know.

Collapse
 
anduser96 profile image
Andrei Gatej

Thanks for sharing!

As far as I know, you can achieve the same result with Promise.all by attaching a ‘.catch()’ to each promise in your array.

Collapse
 
shahzaibkhalid profile image
Shahzaib Khalid

Yes, we could but Promise.allSettled is more concise. 🚀

Collapse
 
amcsi profile image
Attila Szeremi⚡

I think you can only handle the first error that way, not the other errors or successes.