JavaScript: The Hard Parts, v2

Callback Queue and Event Loop Q&A

Will Sentance

Will Sentance

Codesmith
JavaScript: The Hard Parts, v2

Check out a free preview of the full JavaScript: The Hard Parts, v2 course

The "Callback Queue and Event Loop Q&A" Lesson is part of the full, JavaScript: The Hard Parts, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Will fields questions from the audience about what would happen if the one of the functions were to return an augmented variable, a clarification on the previous example, and what would happen if the function's order was augmented.

Preview
Close

Transcript from the "Callback Queue and Event Loop Q&A" Lesson

[00:00:00]
>> Will Sentance: Let's go to Dan, go ahead man.
>> Dan: Tell me if I'm getting in the weeds, but back to the last example where we have the thousand millisecond timeout and it's just waiting. That event loop is just checking. Is there anything on the call sack for that entire second?

[00:00:15]
>> Will Sentance: Yeah, absolutely. The way it's gonna do it is continue to assess if there's any code to run, and then each loop behind the scenes, it's comparing what the timer says is the wait time to what is the current time. And it's gonna constantly check, is enough time passed, and as soon as it has, it's gonna grab that function and execute it.

[00:00:39]
>> Dan: Is that event loop running constantly as long as your browser is open?
>> Will Sentance: As long as our application's running, yeah, yeah. Peter, go ahead.
>> Peter: If, Lock for one second was instead, running our loop for 500 milliseconds and then called Portillo and ran for another 500 milliseconds, would we get that hello?

[00:00:57]
And then @me first, and then when the timer ran out another hello?
>> Will Sentance: Well if we are calling print hello, you say we're calling printHello inside of blockFor1Sec.
>> Peter: Yeah,
>> Will Sentance: Yeah, absolutely. So if we were calling printHello in the conventional sense, and it's did we command that print hello to run?

[00:01:13]
So it's inside a blockFor1Sec, we'd written call printHello ourselves. Well that's synchronous code, that's regular, all your typical global code, not global code, code inside blockFor1Sec. That will just run when we tell it to run. This is when we, did we put any parens on the end of printHello?

[00:01:31]
With set timeout now. We're going to rely with set timeout on that function to be able to run for us and we need very, very strict rules when that can be auto run.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now