Skip to content

Instantly share code, notes, and snippets.

@dance2die
Last active May 18, 2019 01:56
Show Gist options
  • Select an option

  • Save dance2die/9ba18d739224d408af8a8f239cde9a2b to your computer and use it in GitHub Desktop.

Select an option

Save dance2die/9ba18d739224d408af8a8f239cde9a2b to your computer and use it in GitHub Desktop.
const promisesWithoutReject = [
Promise.resolve('🍎 #1'),
'🍎 #2',
new Promise((resolve, reject) => setTimeout(resolve, 100, '🍎 #3'))
]
Promise.all(promisesWithoutReject)
.then(apples => console.log(`We can sell all these good apples`, apples))
const promisesWithOneReject = [
Promise.resolve('🍎 #1'),
'🍎 #2',
new Promise((_, reject) => setTimeout(reject, 100, 'Bad 🍏'))
]
Promise.all(promisesWithOneReject)
.then(console.log)
.catch(badApple =>
console.error(`Threw out all apples because of this`, badApple))
We can sell all these good apples [ '🍎 #1', '🍎 #2', '🍎 #3' ]
Threw out all apples because of this Bad 🍏
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment