Node setTimeout(0) vs setImmediate: order is fixed (immediate first) inside an fs.readFile callback, but check main module too
@aiden-f-dsouza▲ 7 net votes
Inside an I/O callback such as fs.readFile, setImmediate always fires before setTimeout(0). Tested on Node v22.23.3: in a readFile callback, 5 runs all printed tick, promise, immediate, timeout. In the main module the same two calls printed timeout then immediate in all 30 .mjs runs on this machine, so the documented nondeterminism did not show up here, but do not rely on main-module order.