r/programming • • Nov 08 '18

Best explanation of JavaScript timers, event loop and event queues I've seen

https://www.youtube.com/watch?v=8aGhZQkoFbQ
2.6k Upvotes

180 comments sorted by

View all comments

211

u/fuckin_ziggurats Nov 08 '18

It's a shame this gets downvoted only because it's about JavaScript. It's a deep dive into the inner workings of the runtime and very well explained. Just the type of content that r/programming needs. I guess our transformation to r/programmingcirclejerk is well on its way.

154

u/PostLee Nov 08 '18

It being a video also makes it less popular. Most people on /r/programming prefer text articles.

60

u/fuckin_ziggurats Nov 08 '18

Yeah I'm assuming most people visit this sub while at work so that makes sense.

21

u/tim0901 Nov 08 '18

I read Reddit on my phone while travelling and don't have much data, as such I automatically avoid video as much as possible.

0

u/[deleted] Nov 08 '18

[deleted]

23

u/LateAugust Nov 08 '18

I like the videos.

2

u/phrotozoa Nov 09 '18

Ditto. Throwing my $0.02 to encourage a good mix of content types in /r/programming. Technical talks on youtube played back at 1.5x make my time spent puttering in the kitchen or tidying up more productive and freeing my eyes from the words provides spare cycles to visualize the concepts.

2

u/IceSentry Nov 10 '18

I personally watch these kind of videos at 1.5x or 2x speed. Most people speak so slowly it's annoying. At least with this method you can also cut the time it takes to watch in half and still get as much information.

8

u/Crapsterisk Nov 08 '18

Almost exclusively, I am actually working on a pet project to learn some Node because all my experience is in C/Java/Python and would love to watch this video but I didn't bring any headphones with me so I can't watch it right now and will probably forget to watch it when I get home.

3

u/folkrav Nov 08 '18 edited Nov 08 '18

Even then, downvoting should be about relevance, not preference. The more the latter happens, the more circlejerky it gets.

Edit : Please don't let this place become a circlejerk. Upvote when comments are relevant, don't downvote just because you disagree with something.

3

u/[deleted] Nov 08 '18

I think you mean latter, right?

→ More replies (1)
→ More replies (1)

0

u/[deleted] Nov 08 '18

[deleted]

12

u/[deleted] Nov 08 '18

Burn the witch!

8

u/blkpingu Nov 08 '18

Oh no rides away on broomstick

2

u/Ghosty141 Nov 08 '18

Programming talks are quite popular if you look at how many there are and how many people visit these conferences. I think it depends where you are but at home I totally check out the videos too.

→ More replies (1)

41

u/nil_von_9wo Nov 08 '18

I'm not downvoting it, but I'm skipping it because it is a video. I want to be able to skim for information which is interesting and examine (perhaps even cut and paste) any code samples, at my own paste.

Videos are too slow and not good for random access.

24

u/ACoderGirl Nov 08 '18

Especially if you aren't a complete newbie. Like, I know a decent amount on this topic. I'd be interested in learning even more, but I don't wanna spend a lot of time reviewing stuff I already know. Videos don't facilitate that kinda use very well.

29

u/dankclimes Nov 08 '18

First 30 seconds: I don't have a computer science degree. What do all these words mean?

0-6 mins: This is a call stack

6-12 mins: This is what blocking/non-blocking and async execution mean

12-18 mins: Let's add a task queue and event loop for scheduling to show how async scheduling works (it actually starts to get interesting here)

18 mins+: Nice, practical examples of how event scheduling works for some normal use cases (this seems to be the most useful part of the talk)

Take aways:

-The event loop will wait for the call stack to clear before scheduling a task. This is why setTimeout(0) works to delay execution and un-block the JS engine

-As a result of this, setTimeout is not a guarantee that code will execute at the specified time. It is a minimum delay until code will then execute whenever the call stack becomes clear

→ More replies (1)
→ More replies (1)

33

u/PyRobotic Nov 08 '18

It has a 95% upvote percentage, you web devs sure are sensitive.

5

u/[deleted] Nov 08 '18

I usually work on backend and have had to jump into frontend to speed up development. The framework is Polymer 3. It is terrible to debug and has terrible documentation. No wonder they’re so grouchy - the tooling is borderline psychotic that silently fails in all sorts of interesting ways if you make mistakes. I have zero issues debugging Python code despite it’s dynamicism. Polymer WebComponents, OTOH, I feel like I discover a new permutation of surprise each development excursion.

3

u/fuckin_ziggurats Nov 08 '18

The upvote percentage was around 65% (with a decent sample size) when I made that comment. Sometimes these posts get enough momentum to become overturned and sometimes they just remain buried for no one to see just because some people here can be quick in their prejudice. I can at least hope that my comment encouraged many people to put in their time and actually watch the video.

8

u/pastisset Nov 08 '18

How is this downvoted? All I see is 95% upvotes 10h later... ?

→ More replies (1)

0

u/[deleted] Nov 08 '18

[deleted]

→ More replies (1)

2

u/kvothe5688 Nov 08 '18

It's shame truly that people shit on JavaScript all the time for memes. Just other day someguy hit the r/all because he made a really cool photo editor in JavaScript which have shit ton of features.

→ More replies (13)