MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/kpexrj/settimeoutception/ghykjlf/?context=3
r/badcode • u/beckettobrien • Jan 03 '21
35 comments sorted by
View all comments
23
If only there was a way to... loop
12 u/xigoi Jan 03 '21 It's not that easy with setTimeout. You'll need to do some recursive magic. 5 u/Somepotato Jan 03 '21 async/await, multiple outer level timeouts, or callback reuse, done 5 u/[deleted] Jan 03 '21 function delay(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }... await delay(1000); doThing(); await delay (500); doOtherThing();
12
It's not that easy with setTimeout. You'll need to do some recursive magic.
5 u/Somepotato Jan 03 '21 async/await, multiple outer level timeouts, or callback reuse, done 5 u/[deleted] Jan 03 '21 function delay(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }... await delay(1000); doThing(); await delay (500); doOtherThing();
5
async/await, multiple outer level timeouts, or callback reuse, done
5 u/[deleted] Jan 03 '21 function delay(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }... await delay(1000); doThing(); await delay (500); doOtherThing();
function delay(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }
... await delay(1000); doThing(); await delay (500); doOtherThing();
23
u/[deleted] Jan 03 '21
If only there was a way to... loop