Polyfill for Promise.allSettled

Time for a new method to jump in for promises

  • 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',
value,
};
})
.catch((reason) => {
return {
status: 'rejected',
reason,
};
});
});
return Promise.all(mappedPromises);
};

--

--

Javascript Developer

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