Created
September 24, 2019 10:32
-
-
Save harrytwright/3a611b9c56c30b3aa24ae3333efe1711 to your computer and use it in GitHub Desktop.
Promise.allSettled polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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