Skip to content

Instantly share code, notes, and snippets.

@petvas
Last active February 26, 2016 16:14
Show Gist options
  • Save petvas/8088f4843d4ef6df9785 to your computer and use it in GitHub Desktop.
Save petvas/8088f4843d4ef6df9785 to your computer and use it in GitHub Desktop.
Promises Race
/**
* 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