Skip to content

Instantly share code, notes, and snippets.

@oieduardorabelo
Created April 15, 2017 00:20
Show Gist options
  • Save oieduardorabelo/6587ecfd60c8f47521b57eaed8a809ad to your computer and use it in GitHub Desktop.
Save oieduardorabelo/6587ecfd60c8f47521b57eaed8a809ad to your computer and use it in GitHub Desktop.
/**
* Irá printar abaixo:
* esperando... 250
* resolvido com 250
* esperando... 500
* esperando... 1000
*/
test();
async function test() {
const promises = [250, 500, 1000].map(ms => wait(ms));
console.log('resolvido com', await Promise.race(promises));
}
async function wait(ms) {
await new Promise(resolve => setTimeout(() => resolve(), ms));
console.log('esperando...', ms);
return ms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment