mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-29 07:04:09 +08:00
The fs error-first callbacks (readFile, writeFile, stat, access, mkdir and the other callback forms that complete synchronously) and fs.exists delivered their callback through a zero-delay timer. Timers have a 1 ms floor, so every callback waited about 1 ms: 5000 sequential readFile callbacks took 5.5 s, where Node takes about 0.35 s. The callbacks now go on a FIFO queue that the event loop drains like the worker-pool completions: one callback per checkpoint, with nextTicks and microtasks drained between callbacks. A turn delivers the callbacks that were queued when its timers ran, as libuv's poll phase does, so a callback that queues another leaves room for timers and immediates. Corpus 5555 covers the order against the synchronous code and its microtasks, and timers and immediates during a chain of 2000 callbacks.