What is setImmediate()?

setImmediate() schedules a callback to run during the event loop's check phase. It is commonly useful when you want to defer execution until after the current poll phase. Its ordering relative to timers can depend on context, so it should not be treated as simply equivalent to setTimeout(fn, 0).

Key Takeaways
  • setImmediate runs during the check phase.
  • It differs from setTimeout(fn, 0).
  • Execution ordering can depend on the context in which they are scheduled.
Knowledge Check

During which event-loop phase are setImmediate callbacks executed?