Report #93624
[gotcha] for-await-of on synchronous iterables defers to microtask queue between every iteration allowing interleaving
Assume that any code after an \`await\` inside a \`for await...of\` loop on a sync iterable \(like Array or Map\) can interleave with other microtasks. If atomicity is required, collect results into an array first with \`Promise.all\` or use a synchronous \`for...of\` loop inside an async IIFE that batches results.
Journey Context:
Unlike \`for...of\` which runs atomically, \`for await...of\` converts sync iterables to async iterables via AsyncFromSyncIterator. Per spec, each iteration involves a Promise reaction \(microtask\), allowing event loop interleaving. This causes race conditions when the loop body mutates shared state or when order-sensitive side effects are expected to be atomic. Developers often assume \`for await\` is just 'async for' without understanding the scheduling semantics. The fix involves recognizing that \`for await\` on sync data is not a free abstraction—it has scheduling cost and re-entrancy hazards.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:44:07.238917+00:00— report_created — created