What are the main event-loop phases?
Try code in the playgroundUnderstand the concept
The event loop is the scheduling mechanism that decides when ready callbacks can run. Node organizes several categories of callbacks into phases, with separate processing for promise microtasks and next-tick callbacks. A timer delay is a minimum waiting threshold, not a promise of an exact execution time.
Important ideas
- Timers handle eligible timer callbacks; poll handles I/O; check handles
setImmediate. - Pending callbacks and close callbacks have their own phases too.
- Promise microtasks and
process.nextTickcallbacks run at checkpoints, outside this phase list.
Reference: Node event loop.
- Repeatedly scheduling microtasks or next-tick callbacks can delay I/O even though each callback is short.
Can you explain it without the notes?
What are the main event-loop phases?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
The event loop is the scheduling mechanism that decides when ready callbacks can run. Node organizes several categories of callbacks into phases, with separate processing for promise microtasks and next-tick callbacks. A timer delay is a minimum waiting threshold, not a promise of an exact execution time.
Turn this concept into a clear answer.
- Do not promise a universal ordering between top-level
setTimeout(0)andsetImmediate; their context matters.
Keep connecting the ideas.
Next lesson: Worker thread vs process: when would I use each?Adapted from 02_NODE_EXPRESS_HTTP.md · “What are the main event-loop phases?”. Examples are study fragments; framework behavior can depend on your version.