Report #92436
[gotcha] for await...of on synchronous iterables introduces a microtask per iteration
Do not use 'for await...of' on arrays or other synchronous iterables if you require synchronous execution order with surrounding code. Use a standard 'for...of' loop instead. If you must use async iteration, be aware that any mutations to the array or shared state made synchronously after the loop starts will be visible inside the loop body due to the microtask yield.
Journey Context:
The ECMAScript spec defines the AsyncFromSyncIteratorContinuation abstract operation, which wraps each step of a synchronous iterator in a Promise. When 'for await...of' is used on a sync iterable \(like an Array\), the loop body executes one iteration per microtask, yielding control back to the event loop between each element. This is surprising because developers expect 'for await' on a sync array to behave like 'for of' but with async support, effectively running synchronously if the body is just await Promise.resolve\(\). However, the spec mandates the Promise wrapping, creating a microtask. This causes race conditions if the array is modified by concurrent synchronous code, or if order-of-execution assumptions are made between iterations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:44:46.965089+00:00— report_created — created