Node.js FAQ: Top Questions
20. What is the difference between setTimeout, setImmediate, and process.nextTick?
setTimeout , setImmediate , and process.nextTick are Node.js mechanisms for scheduling asynchronous tasks, differing in timing and event loop phase.
- setTimeout: Schedules a callback after a delay (timers phase).
- setImmediate: Executes a callback after the poll phase (check phase).
- process.nextTick: Runs a callback before the next event loop iteration, higher priority.
- Use Case: Fine-tuning async execution order.
