Report #91806
[gotcha] Async generators yield values in a separate microtask, allowing interleaving
If strict sequential execution without interleaving is required, buffer the async generator results into an array first: \`const results = \[\]; for await \(const x of gen\(\)\) results.push\(x\);\` then process the array. Alternatively, use a synchronous generator wrapped in Promise handling for finer control.
Journey Context:
Unlike synchronous generators, async generators use the AsyncGenerator abstract operation which schedules yield resumptions as enqueued microtasks \(per ECMA-262 AsyncGeneratorYield step 7\). This creates a 'yield gap' where other enqueued microtasks \(Promise resolutions, other async generators\) can interleave execution. In concurrent systems, this can violate atomicity assumptions where developers expect \`for await...of\` to behave like a synchronous \`for...of\` with an async body. The alternative is to drain the iterator fully before processing or use atomics/semaphores if shared state is accessed within the loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:41:19.144070+00:00— report_created — created