Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const promise1 = Promise.resolve('foo');
const promise2 = Promise.reject('bar')
const promises = [promise1, promise2];
Promise.allSettled(promises).
then((results) => {
for (const result of results) {
if (result.status === 'fulfilled') console.log(result.value, 'is fulfilled');
if (result.status === 'rejected') console.log(result.reason, 'is rejected');
}
console.log(JSON.stringify([...results]));
});
// "foo is fulfilled"
// "bar is rejected"
// "[{"status":"fulfilled","value":"foo"},{"status":"rejected","reason":"bar"}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.