Polyfill for Promise.allSettled

The Promise.allSettled() method returns a promise that resolves after all of the given promises have either resolved or rejected, with an array of objects that each describe the outcome of each promise.

Right now Promise.all is in the proposal state. It is in stage 4 presets.

Personally I felt this was much needed and I had a lot of use cases where I could use something like this.

Status and reason is something which is introduced new here.

  • status: It is fulfilled when the promise is resolved and rejected when the promise gets rejected.
  • value: This represents the response of a fulfilled promise. It’s not present for rejected promises.
  • reason: This tells you the reason why your promise got rejected.
Promise.allSettled = function (promises) {
let mappedPromises = promises.map((p) => {
return p
.then((value) => {
return {
status: 'fulfilled',
.catch((reason) => {
return {
status: 'rejected',
return Promise.all(mappedPromises);

The only difference this creates is, it allows you to not worry about what might fail or succeed and will give you the result irrespective of how many promises fail.
The problem with Promise.all was it will fail even if one promise is rejected (not really a problem, more like depends on your use case) and because of that, you won’t be able to rely on it if in your case you still want to go ahead with the rest of the responses or probably take care of the errors.

For more information do give this a read https://github.com/tc39/proposal-promise-allSettled

Thanks for reading. I hope you found this useful


Javascript Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

1. JavaScript Functions

20 JavaScript Concepts you should know as a JavaScript Programmer!

I am getting cheaper pricing for hosting from other providers. Why is your price high?

Evolution of a Node.js API, Zoe.js — MongoDB

Hack the World: How We Bent Aptify Web to Our Will

The Most Important Tips to Help You Prepare a Programming Resume

“Hello World” on CupCarbon v3.8.2

The most frequently used javaScript array methods

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yash Sharma

Yash Sharma

Javascript Developer

More from Medium

How JS works behind the scenes?

Currying in JS | sum(1)(2)(3)….()

Getting Closure with Javascript

The difference between .innerText, .textContent and .innerHTML