Created
September 21, 2019 07:00
-
-
Save ppeeou/c99c27c30fe250dbaf0e005f9561c801 to your computer and use it in GitHub Desktop.
This file contains 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
// -- simple | |
function isIterator(obj) { | |
return !!obj && !!obj[Symbol.iterator]; | |
} | |
function allSettled(iterable) { | |
if (!isIterator(iterable)) { | |
throw new Error('[allSettled] first param must be iterable'); | |
} | |
const onFulfill = v => ({ status: 'fulfilled', value: v }); | |
const onReject = v => ({ status: 'rejected', reason: v }); | |
return Promise | |
.all(Array.from(iterable).map(p => | |
Promise | |
.resolve(p) | |
.then(onFulfill) | |
.catch(onReject))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment