Skip to content

Instantly share code, notes, and snippets.

@solominh
Created January 24, 2017 14:15
Show Gist options
  • Save solominh/c3e8d0a593ada9cb2d7e3231eb64dca6 to your computer and use it in GitHub Desktop.
Save solominh/c3e8d0a593ada9cb2d7e3231eb64dca6 to your computer and use it in GitHub Desktop.
var timer = (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms)
});
}
promises = [timer(3000), timer(5000), timer(1000), timer(2000)]
async function doSomething() {
promises.forEach(async function (promise, idx) {
console.log('Await promise', idx);
let returnValue = await promise;
console.log('Result', idx);
})
}
doSomething().then( ()=> {
console.log('Finish')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment