Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardNodeJSevent loop phasesSingle-choice MCQ

Inside an fs.readFile callback (i.e. running in the poll phase), why is setImmediate guaranteed to fire before a setTimeout(fn, 0) registered in the same callback?

const fs = require('fs'); fs.readFile(__filename, () => { setTimeout(() => console.log('timeout'), 0); setImmediate(() => console.log('immediate')); }); // Always prints: immediate, then timeout