Created
October 8, 2020 07:52
-
-
Save subhog/1d406c6eb3b1e0b35d4f73fcfbf5dcad to your computer and use it in GitHub Desktop.
Async loop example
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
const CHANGE = true; | |
let calculate = () => { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve(5) | |
}, 100); | |
}) | |
} | |
(async () => { | |
let value = 4; | |
if(CHANGE) { | |
value = await calculate(); | |
} | |
for(let i = 0; i < 200; i += 1) { | |
if(CHANGE) { | |
value = await calculate(); | |
} | |
} | |
console.log(value); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment