DEV Community

loading...

Discussion on: Asynchronous Javascript - 02 - The Event Loop

Collapse
ilya_sher_prog profile image
Ilya Sher

checking if there’s at least one function in the call stack, and if so, jumps the program execution to that of the function at the top of the call stack.

The event loop code is typically not running when there is something in the call stack. That's because if there is something on the call stack - that code is running.

It's called event loop not because it checks whether there is something on the call stack all the time but because it checks for the tasks queue in a loop.

From developer.mozilla.org/en-US/docs/W... :

while (queue.waitForMessage()) {
  queue.processNextMessage()
}

and

Each message is processed completely before any other message is processed.

This offers some nice properties when reasoning about your program, including the fact that whenever a function runs, it cannot be pre-empted and will run entirely before any other code runs (and can modify data the function manipulates)

Collapse
kabir4691 profile image
Kabir Nazir Author

Cool. I shall revisit the concepts and update this soon.

Collapse
ilya_sher_prog profile image
Ilya Sher • Edited

it is a loop that runs over and over again, checking if there’s at least one function in the call stack

It's been a while. Can you please fix? People are reading this and getting the wrong impression.