Created
July 27, 2017 22:53
-
-
Save prof3ssorSt3v3/c4eea8742fd3a082d1e119b30acf5be6 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
// Promise.race() | |
// when you only want the result from the first | |
// resolved promise | |
// | |
let p1 = Promise.reject(111); | |
let p2 = Promise.resolve(222); | |
let p3 = new Promise((resolve, reject)=>{ | |
setTimeout(resolve, 1000, 333); | |
}); | |
Promise.race([p3, p2, p1]) | |
.then((result)=>{ | |
console.log('winning:', result); | |
}) | |
.catch((result)=>{ | |
console.log('Failed:', result); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment