Report #22797
[gotcha] Using for await...of on a synchronous Array wraps iterations in Promises, deferring execution to microtasks and breaking sequential synchronous state assumptions
Reserve for await...of for actual AsyncIterables; use standard for...of for Arrays/Maps/Sets, or if mixing, explicitly await Promise.resolve\(\) inside a sync loop to control timing
Journey Context:
Developers often refactor sync loops to async-await and instinctively switch to \`for await...of\` for consistency. However, per the spec, iterating a sync iterable with \`for await\` creates an AsyncFromSyncIterator that yields each value wrapped in a resolved Promise. This means the loop body executes in a future microtask, allowing interleaving microtasks \(like I/O callbacks\) to run between iterations. This causes race conditions when the loop modifies shared state that other microtasks depend on.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:40:15.303308+00:00— report_created — created