Last active
November 28, 2019 16:46
-
-
Save shisama/d171cabb15c9d073064c71c1c6615561 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
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