70
u/SusansMeatScepter Jan 03 '21
I am speed
14
u/beckettobrien Jan 03 '21
Yup! I added a variable so I could test out later parts of it without waiting a very long time to get to them
23
Jan 03 '21
If only there was a way to... loop
2
u/beckettobrien Jan 03 '21
Yeah, I probably could have found a better way to do it looking back so it could be, uh, more readable. It isn’t quite straightforward enough to use a loop because I also have each timeout call a function with a different argument each time, but it probably would be easier to have an array of objects that contain the function to run and the timeout so I could loop over it and have less of a headache, but it’s not for anything important so I don’t care :)
12
u/xigoi Jan 03 '21
It's not that easy with setTimeout. You'll need to do some recursive magic.
10
Jan 03 '21 edited Jan 03 '21
Or just recursion, with an index that's passed into the function.
Something kind of like:
const timeoutList = [1500, 3000, (full list of timeouts)]; function setTimeoutFromArr(idx, cb) { if (idx >= timeoutList.length) return; setTimeout(() => { cb(); setTimeoutFromArr(idx++, cb); }, timeoutList[idx]); } setTimeoutFromArr(0, someCbFuncToRerunHere);Untested, but hopefully you get the idea.
Edit: can't get it to format, just use the automod link I guess. It's my first time writing a code block here from mobile, sorry
→ More replies (1)→ More replies (2)5
u/Somepotato Jan 03 '21
async/await, multiple outer level timeouts, or callback reuse, done
5
Jan 03 '21
function delay(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }... await delay(1000); doThing(); await delay (500); doOtherThing();
49
u/OkPreference6 Coding The Declaration of Independance Jan 03 '21
Whoever transcribes this post deserves an award.
27
Jan 03 '21
It's
}, speed ? 10 : 5000on every line where the last 5000 is varying from around 1000 to 10000, always a multiple of 500, and the indentation level is decreasing for every new line, going from the top right to the bottom left.I've always wondered how actually useful the code spam transcriptions really are. I know the transcriptions aren't just for people who rely on text to speech, but that's at least part of the reason why they're done.
7
23
14
6
Jan 03 '21
Imagine one day having the ability to do this more efficiently. I don't know, maybe something called a "loop"? Just throwing out some random ideas ya know.
1
1
1
109
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!