Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function logWinner (p1, p2) {
Promise.race([p1, p2]).then(console.log.bind(console));
}
var p1 = new Promise(function(resolve) {
setTimeout(function() { resolve('p1'); }, 20);
});
var p2 = new Promise(function(resolve) {
setTimeout(function() { resolve('p2'); }, 10);
});
setTimeout(function() { logWinner(p1, p2); }, 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.