Async Traps
Event Loop
setImmediateruns after I/O —process.nextTickruns before (order matters)- Long loops starve I/O — break with
setImmediateevery N iterations
Promises
Promise.all()fails fast — one rejection kills all, useallSettledfor partial results- Forgetting
await— function continues without waiting, no error thrown return awaitredundant — except inside try/catch (needed to catch rejection)- Sequential
awaitin loop is slow — usePromise.all(items.map(...))for parallel
Callbacks
- Callback errors don't propagate — try/catch won't catch them, handle in callback
- Zalgo: mixing sync/async — always be consistent, async callback even for cached values