When the time is due for a scheduled setTimeout, the task is to run its callback.When a user moves their mouse, the task is to dispatch mousemove event and execute handlers.When an external script loads, the task is to execute it.The JavaScript engine does nothing most of the time, it only runs if a script/handler/event activates. That’s a formalization for what we see when browsing a page. Sleep until a task appears, then go to 1.execute them, starting with the oldest task.There’s an endless loop, where the JavaScript engine waits for tasks, executes them and then sleeps, waiting for more tasks. In this chapter we first cover theoretical details about how things work, and then see practical applications of that knowledge. Understanding how event loop works is important for optimizations, and sometimes for the right architecture. Browser JavaScript execution flow, as well as in Node.js, is based on an event loop.
0 Comments
Leave a Reply. |