r/badcode • • Jan 03 '21

js setTimeoutception

Post image
719 Upvotes

35 comments sorted by

109

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '21

Image Transcription: Code


                                                                                                                                       }, speed ? 10 : 1500)
                                                                                                                                   }, speed ? 10 : 3000)
                                                                                                                               }, speed ? 10 : 1500)
                                                                                                                           }, speed ? 10 : 3500)
                                                                                                                       }, speed ? 10 : 2500)
                                                                                                                   }, speed ? 10 : 4000)
                                                                                                               }, speed ? 10 : 2000)
                                                                                                           }, speed ? 10 : 2500)
                                                                                                       }, speed ? 10 : 7000)
                                                                                                   }, speed ? 10 : 1500)
                                                                                               }, speed ? 10 : 4000)
                                                                                           }, speed ? 10 : 3500)
                                                                                       }, speed ? 10 : 6000)
                                                                                   }, speed ? 10 : 2500)
                                                                               }, speed ? 10 : 4000)
                                                                           }, speed ? 10 : 3000)
                                                                       }, speed ? 10 : 2500)
                                                                   }, speed ? 10 : 5000)
                                                               }, speed ? 10 : 3000)
                                                           }, speed ? 10 : 15000)
                                                       }, speed ? 10 : 5000)
                                                   }, speed ? 10 : 3000)
                                               }, speed ? 10 : 10000)
                                           }, speed ? 10 : 10000)
                                       }, speed ? 10 : 3000)
                                   }, speed ? 10 : 2000)
                               }, speed ? 10 : 1500)
                           }, speed ? 10 : 1500)
                       }, speed ? 10 : 2500)
                   }, speed ? 10 : 2000)
               }, speed ? 10 : 4000)
           }, speed ? 10 : 2000)
       }, speed ? 10 : 4000)
   }, speed ? 10 : 3000)
, speed ? 10 : 1500)
eed ? 10 : 2000)
? 10 : 5000)
 : 3000)

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!

19

u/beckettobrien Jan 03 '21

Wow. I am very sorry

8

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '21

Don't be! I chose to do this post, after all. :)

70

u/husao Jan 03 '21

poor human,
good human,
little ball of strength.

wilful human,
determined human,
purr, purr, purr

29

u/Master_Sifo_Dyas Jan 03 '21

Impressive work transcribing that horror of a program

I just saw a mass of white and light purple text on a dark background

11

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '21

Thank you!

→ More replies (1)

5

u/Aseriam Jan 03 '21

Good human

2

u/samtonatorn Jan 03 '21

This rendners so cool on phone!

0

u/[deleted] Jan 03 '21

[deleted]

4

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '21

Yup :) Got a lot of free time

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

u/[deleted] 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

u/[deleted] 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)

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();

→ More replies (2)

49

u/OkPreference6 Coding The Declaration of Independance Jan 03 '21

Whoever transcribes this post deserves an award.

27

u/[deleted] Jan 03 '21

It's }, speed ? 10 : 5000 on 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

u/AlFasGD Jan 03 '21

One of them is 15000, larger than 10000

23

u/Not_Sugden Jan 03 '21

what the fuck? full sauce ?

14

u/SuperSupermario24 while True: print("owo") Jan 03 '21

What the fuck is this even for?

9

u/[deleted] Jan 03 '21

My guess would be for some sequential animations or something to that nature.

6

u/[deleted] 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

u/_Guigui Jan 03 '21

I am speed

1

u/TerabyteF Jan 08 '21

The person who can read this must be Hulk or something like that...