Skip to content

Instantly share code, notes, and snippets.

@khaosdoctor
Created April 7, 2019 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khaosdoctor/2093905c92b3f8b77f3f81a838e06726 to your computer and use it in GitHub Desktop.
Save khaosdoctor/2093905c92b3f8b77f3f81a838e06726 to your computer and use it in GitHub Desktop.
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