Last active
February 26, 2016 16:14
-
-
Save petvas/8088f4843d4ef6df9785 to your computer and use it in GitHub Desktop.
Promises Race
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
/** | |
* Promises Race | |
*/ | |
(function () { | |
var promises = [ | |
Promise.resolve('1st'), | |
Promise.resolve('2nd'), | |
Promise.resolve('...'), | |
Promise.resolve('n'), | |
]; | |
/** | |
* Promise Race with one `then` for all | |
*/ | |
Promise.race(promises).then(console.log.bind(console)); | |
/** | |
* Promise Race with own `then` for all | |
*/ | |
Promise.race(promises).then( | |
console.log.bind(console), //Call if 1st is the fastest | |
console.log.bind(console), //Call if 2nd is the fastest | |
console.log.bind(console), //Call if 3rd is the fastest | |
console.log.bind(console) //Call if 4th is the fastest | |
); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment