Created
April 7, 2019 18:59
-
-
Save khaosdoctor/2093905c92b3f8b77f3f81a838e06726 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
function reflect(promise) { | |
return promise.then( | |
(v) => { | |
return { status: 'fulfilled', value: v }; | |
}, | |
(error) => { | |
return { status: 'rejected', reason: error }; | |
} | |
); | |
} | |
const promises = [ fetch('index.html'), fetch('https://does-not-exist/') ]; | |
const results = await Promise.all(promises.map(reflect)); | |
const successfulPromises = results.filter(p => p.status === 'fulfilled'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment