Skip to content

Instantly share code, notes, and snippets.

@khaosdoctor
Created April 7, 2019 18:45
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 khaosdoctor/0d640441fc8319db81fb20fbb5d884a0 to your computer and use it in GitHub Desktop.
Save khaosdoctor/0d640441fc8319db81fb20fbb5d884a0 to your computer and use it in GitHub Desktop.
const p1 = Promise.race([
new Promise(resolve => setTimeout(resolve, 4000)),
new Promise((resolve, reject) => setTimeout(reject, 8000))
])
const p2 = Promise.race([
p1,
new Promise(resolve => setTimeout(resolve, 6000)),
new Promise(resolve => setTimeout(resolve, 10000)),
new Promise((resolve, reject) => setTimeout(reject, 2000))
])
p2.then(result => console.log(result))
p2.catch(err => console.error(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment