Created
January 11, 2017 14:28
-
-
Save tedwong/eae1683740b4841ea096fe11b99ed912 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
var p1 = new Promise((resolve, reject) => { | |
setTimeout(resolve, 2000, "long_execution"); | |
}); | |
var p2 = new Promise((resolve, reject) => { | |
setTimeout(resolve, 500, "ok"); | |
}); | |
var p3 = new Promise((resolve, reject) => { | |
setTimeout(reject, 1000, "reject"); | |
}); | |
Promise.race([p1, p3]).then(values => { | |
console.log(values); | |
}, reason => { | |
console.log(reason) | |
}); | |
Promise.race([p2, p3]).then(values => { | |
console.log(values); | |
}, reason => { | |
console.log(reason) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment