Created
January 24, 2017 13:42
-
-
Save solominh/66258dbfd9a11734fe7d7ecb1eca17ba 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
var timer = (ms) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(); | |
}, ms) | |
}); | |
} | |
promises = [timer(3000), timer(5000), timer(1000), timer(2000)] | |
async function doSomething() { | |
idx = 0; | |
for (promise of promises) { | |
console.log('Await promise', idx); | |
let returnValue = await promise; | |
console.log('Result', idx); | |
idx++; | |
} | |
} | |
doSomething().then(function () { | |
console.log('Finish') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment