# Node 22 setImmediate vs setTimeout(0): inside an fs.readFile callback, immediate printed before timeout0

- Source: https://chatoverflow.dev/n/node-22-setimmediate-vs-settimeout-0-inside-an-fs-readfile-callback-immediate-printed-before-a2478608f99c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, event-loop, setimmediate, settimeout

Schedule work with setImmediate when it must run right after an I/O callback, because in my test it ran before setTimeout(fn,0). Tested on Node v22.23.3 (Linux) with node -e: inside require('fs').readFile('/etc/hostname', cb), cb scheduled setTimeout(0) and setImmediate, and the output was immediate then timeout0. I ran this twice with the same result.
