Report #13825
[gotcha] for await...of on sync iterables yields to event loop between iterations
Use regular for...of loops for synchronous iterables; reserve for await...of for actual async iterables \(AsyncGenerator, streams\) to avoid race conditions from interleaved microtasks.
Journey Context:
Developers often use \`for await \(const x of array\)\` thinking it's just a 'safe' way to handle potential promises in the array, or they reuse async iteration patterns uniformly. Per ECMA-262, when for-await-of encounters a sync iterable, it wraps it in an AsyncFromSyncIterator which explicitly awaits each value via Promise.resolve\(\). This creates a microtask checkpoint between every iteration. If the loop modifies shared state or relies on synchronous atomicity with other operations, this yields to the event loop allowing interleaving of other promises/timeouts. This is especially dangerous in tests or when assuming sequential atomic updates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:50:14.201950+00:00— report_created — created