Suppose i am running some code inside a setInterval. That is, a bunch of code is begin run every 33ms or so.
Inside this bunch of code is a function, lets call it the Overlord function, which executes other functions depending the values of some state variables.
The question is this:
Suppose Overlord executes function1. Suppse that function1 has not finished running after 33ms (or whatever the interval length is) . Then Overlord executes function2 while function1 is presumably still running. What happens?
Does function1 finish before javascript runs function2? Is there some sort of que built into javascript execution?
Thank you!
Javascript is single threaded, so the second function will be queued, but cannot be executed until the first has finished executing. That said, if your function takes more than 33ms to execute, it might be a good idea to break it into small asynchronous chunks (in order to prevent locking up the interface).