-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Given answer:
The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn't start processing the event loop until the async function has finished executing the code. Note: It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.
From what I have learned from the external sources, the event loop is not actually a queue but a mechanism that works by continuously checking the call stack to see if there are any functions waiting to be executed. If the call stack is empty, the event loop checks the callback queue for any pending events. If there are any events, the event loop will pop the first event off the queue and add it to the call stack.
The MDN docs even describe the event loop implementation similar to:
while (queue.waitForMessage()) {
queue.processNextMessage();
}
P.S. Thank you for compiling all the questions. It's really helpful for my revision.