Created
April 15, 2017 00:20
-
-
Save oieduardorabelo/6587ecfd60c8f47521b57eaed8a809ad 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
/** | |
* 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