Skip to content

Instantly share code, notes, and snippets.

@subhog
Created October 8, 2020 07:52
Show Gist options
  • Save subhog/1d406c6eb3b1e0b35d4f73fcfbf5dcad to your computer and use it in GitHub Desktop.
Save subhog/1d406c6eb3b1e0b35d4f73fcfbf5dcad to your computer and use it in GitHub Desktop.
Async loop example
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