Report #73782
[gotcha] for await...of on sync arrays introduces microtask delays causing race conditions
Use standard \`for...of\` loops for synchronous iterables, even inside async functions. Only use \`for await...of\` when iterating actual async iterables or generators. If you must use \`for await...of\` on an array, be aware that each iteration yields to the microtask queue, allowing interleaving with other Promise-based code.
Journey Context:
The \`for await...of\` syntax is designed for async iterables, but JavaScript allows it on sync iterables too via AsyncFromSyncIterator. The spec mandates that each iteration wraps the value in \`Promise.resolve\(\)\`, creating a microtask delay. This means \`for await...of\` on an array behaves very differently from \`for...of\` regarding event loop timing. Developers often mistakenly use \`for await...of\` on arrays thinking it's 'the async way,' only to encounter subtle race conditions where interleaved microtasks modify shared state between iterations. The performance is also worse due to the microtask overhead. The rule is simple: sync data gets \`for...of\`, async data gets \`for await...of\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:26:29.253266+00:00— report_created — created