0
0
Node.jsframework~5 mins

Event loop phases and timer execution in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the event loop in Node.js?
The event loop is a process that handles asynchronous callbacks in Node.js. It allows Node.js to perform non-blocking operations by offloading tasks and executing callbacks when ready.
Click to reveal answer
intermediate
Name the main phases of the Node.js event loop.
The main phases are: timers, pending callbacks, idle/prepare, poll, check, and close callbacks. Each phase has a specific role in processing callbacks and events.
Click to reveal answer
beginner
What happens during the 'timers' phase of the event loop?
During the timers phase, callbacks scheduled by setTimeout() and setInterval() are executed if their time has expired.
Click to reveal answer
intermediate
How does the 'poll' phase work in the event loop?
The poll phase waits for new I/O events and executes their callbacks. If there are no timers to run, it will wait for callbacks or new events to arrive.
Click to reveal answer
intermediate
Why might a timer callback be delayed in Node.js?
Timer callbacks can be delayed if the event loop is busy running other callbacks or if the poll phase is waiting for I/O. Timers only run after their delay and when the event loop reaches the timers phase.
Click to reveal answer
Which event loop phase executes callbacks from setTimeout()?
Acheck
Bpoll
Ctimers
Dclose callbacks
What does the poll phase do in the Node.js event loop?
AExecutes close callbacks
BExecutes setImmediate callbacks
CRuns timer callbacks
DWaits for and processes I/O events
When are setImmediate() callbacks executed?
ADuring the check phase
BDuring the poll phase
CDuring the timers phase
DDuring the close callbacks phase
If the event loop is busy, what happens to timer callbacks?
AThey are delayed until the event loop is free
BThey are skipped
CThey run immediately
DThey run during the poll phase
Which phase runs callbacks for socket or handle close events?
Atimers
Bclose callbacks
Ccheck
Dpoll
Explain the sequence of event loop phases and how timer callbacks are executed in Node.js.
Think about how the event loop cycles through phases and when timers get their turn.
You got /5 concepts.
    Describe why a setTimeout callback might not run exactly after its delay time in Node.js.
    Consider what else the event loop might be doing when the timer expires.
    You got /4 concepts.