Created
August 8, 2018 09:08
-
-
Save ken-master/ee03672d955d430d6d20ab8a202949f2 to your computer and use it in GitHub Desktop.
Async Await with promise inside loop
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
(async () => { | |
for (let i = 0; i < 100; i++) { | |
await something(i) | |
await delay(i); | |
} | |
console.log("LOOP FINISHED"); | |
})(); | |
function delay(i) { | |
return new Promise((resolve, reject) => { | |
console.log("Done " + i + " Iteration" ); | |
setTimeout(resolve, 1000); | |
}); | |
} | |
function something(i) { | |
return new Promise((resolve, reject) => { | |
console.log("Ken was here " + i ); | |
setTimeout(resolve, 2000); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment