Skip to content

Instantly share code, notes, and snippets.

@harrytwright
Created September 24, 2019 10:32
Show Gist options
  • Save harrytwright/3a611b9c56c30b3aa24ae3333efe1711 to your computer and use it in GitHub Desktop.
Save harrytwright/3a611b9c56c30b3aa24ae3333efe1711 to your computer and use it in GitHub Desktop.
Promise.allSettled polyfill
if (!Promise.allSettled) {
// Polyfill
Promise.prototype.allSettled = function(values) {
if (this == null) {
throw new TypeError('this is null or not defined');
}
return this.all(values.map(reflect));
};
function reflect(promise) {
return promise.then(
(v) => {
return { status: 'fulfilled', value: v };
},
(error) => {
return { status: 'rejected', reason: error };
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment