Skip to content

Instantly share code, notes, and snippets.

@adamwatters
Created November 17, 2016 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamwatters/4c88bfa51e469ccaa329f33cf303e1b7 to your computer and use it in GitHub Desktop.
Save adamwatters/4c88bfa51e469ccaa329f33cf303e1b7 to your computer and use it in GitHub Desktop.
what the heck is the event loop?

What is the JS event loop?

How does JS even work?

  • v8 (chromes run time)
  • single threaded
  • callbacks

js says...

"a signle-threaded non-blocking asynchronous concurrent language" "i have a call stack, an event loop, a callback queue, and some other apis"

v8 says... "i have a call stack and a heap"

the call stack one thread == one call stack == on thing at a time

call stack records where we are in the program

"blowing the stack" => too many functions (infinite recur)

Concurrency & the Event Loop

one thing at a time, except not really runtime can only execute one line of code at a time BUT Browser is more than just runtime! Calling WebAPIs opens additional threads outside js (In node, this is C++ APIS)

webAPI finishes, pushes callback onto TASK QUEUE event loop continuously checks stack when stack is empty, moves callback off TASK QUEUE and pushes onto hte stack

eg setTimeOut(0, callback) defers callback until stack is empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment