-
Notifications
You must be signed in to change notification settings - Fork 0
event loop
Emily Yu edited this page Apr 3, 2018
·
1 revision
- call stack: keeps track of what function is currently executing and which function is to be executed after that
- event table: keeps track of when specific functions should be triggered after specific events
- event queue: receives function calls from the event table and sends them to the call stack in the correct order
- constantly running process
- checks if call stack is empty, and if it is and there is something in the event queue, moves that something to the call stack
- even if the delay is 0 milliseconds, calling a function within a setTimeout will send it to the event table and on to the back of the event queue
- using this, if you want to purposely mae a huge number of recursive calls you can avoid stack overflow in a hacky way by wrapping your recursive calls in a setTimeout with a delay of 0--the calls will then go through the event table and queue instead of piling up on the stack directly