Event loop
An event loop, as its name implies, is a loop. What this loop does is, when a new task is supposed to be executed, the event loop queues this task. Now from here, the control shifts to the event loop. When the event loop runs, it checks whether there is some task in its queue or not. If there is a task present, the control switches to the task.
Now, here is the interesting part in the context of the asynchronous execution of tasks. Suppose there are two tasks, namely Task A and Task B, in the queue of the event loop. When the event loop starts executing, it checks the status of the task queue it has. The event queue finds out that there are tasks in its queue. So, the event queue picks up Task A. Now a context switch happens ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access