Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active November 28, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shisama/d171cabb15c9d073064c71c1c6615561 to your computer and use it in GitHub Desktop.
Save shisama/d171cabb15c9d073064c71c1c6615561 to your computer and use it in GitHub Desktop.
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