Transcript from the "Web API Rules" Lesson
>> Will Sentance: Go ahead Mark.
>> Will Sentance: Which function?
>> Mark: Print, I'm sorry, set time out.
>> Will Sentance: Set time out, yes. Or after our facade, our function that triggers stuff in the web browser, yeah, yeah.
>> Mark: The web browser then is directly affecting the stack at a later date- [SOUND] In some-
>> Will Sentance: That seems insane, right?
>> Mark: Yeah, that seems strange and what if the stack has got stuff in it?
[00:00:39] That can't be right. Yeah, Braden.
>> Braydon: What about the zero millisecond example?
>> Braydon: Where did that one-
>> Will Sentance: Yeah, hold on. What about zero milliseconds? Why did the function not just come out into here and then come straight back home and run? Great question Braden, Jason?
>> Braydon: Excuse me.
[00:01:00] The printHello function, when we transfer it, is the set time and I don't remember the implementation, is set timeout memorized so the bits that make up printHello, are they stored in we'll say it's the V8 execution context?
>> Will Sentance: So here we're hinting at something around. Hold on, does that printHello function get to hold onto any state around it?
[00:01:25] Suppose it needs to use some other data around it, does that data get held onto? Well, where do you think that data gets held onto, people? In the?
>> Braydon: Backpack.
>> Will Sentance: In the backpack, exactly. Spreading, spreading.
>> Braydon: The note or-
[00:02:57] If we want to speak to the Internet, we're gonna do it in the background of the web browser. If we wanna do a timer, we're gonna do it in the background of the web browser so we don't block any further code in our single threaded language from running.
>> Peter: Just run a for loop.
>> Will Sentance: For loop, Jason, you're gonna say the same thing?
>> Peter: Yeah, for loop, timer, something to occupy.
>> Will Sentance: Well, not a timer, cuz a timer's gonna happen down here. So, a for loop is exactly right as you say as well, Jason. It's gonna block the thread for one second, so maybe like a for loop adding I don't know, I need to find this out. Maybe adding like three million elements to an array, that's gonna take maybe about a second.
[00:03:55] And that's how we can block it. Then we're gonna be able to set timeout, we're already by the way, not unfamiliar with that with Braden zero millisecond wait. Then we're gonna call our block for one second. And then we're gonna call first. Now I assume, of course, the printHello is gonna run immediately at zero milliseconds.
[00:04:16] Mm-hm, we're gonna need to have some pretty fundamental rules about how our code is going to run