On each iteration of the event loop callbacks are run in the following order:
- Run initial script
- -> Run Next Tick callbacks.
- Run Timer callbacks: All active timers scheduled for a time before the loop’s concept of now get their callbacks called.
- -> Run Next Tick callbacks.
- Run Pending I/O callbacks: If the previous iteration deferred any I/O callback it will be run at this point.
- -> Run Next Tick callbacks.
- Run Current I/O callbacks: At this point the loop will block for I/O (with a previously calculated timeout), all I/O related handles that were monitoring a given file descriptor for a read or write operation get their callbacks called at this point.
- -> Run Next Tick callbacks.
- Run Immediate callbacks: The entire callback queue is processed every event loop iteration.
- -> Run Next Tick callbacks.
- Go to step 2: Start new cycle