Thanks for this awesome summary, helped clarify things for me! The illustrations are awesome.
I do have a question, however.
You write for step 19 (after the setTimeout
has been called but before the callback starts executing) that “At this point the call stack and task queue are both empty. At the same time a timeout is counting down (5 seconds), but the corresponding timeout callback has not been scheduled yet.” Where exactly is the callback execution instruction “stored,” then, if not in the stack and not in a task queue? In your diagram, you’ve put it inside the “API’s” box. But what exactly is that box? Is it a separate kernel thread? If so, why doesn’t Node stop running (e.g., does Node magically know to wait for execution to complete on certain privileged kernel threads before ending its own execution)?