Report #40771
[gotcha] Async generator return values are silently discarded by for-await-of loops
Do not rely on the return value of an async generator when using \`for await...of\`. Instead, yield the final value as a normal value before returning, or manually iterate using \`.next\(\)\` calls to capture the \`\{ done: true, value: finalValue \}\` result.
Journey Context:
Developers familiar with sync generators expect the return value to be available after a \`for...of\` loop completes. However, ECMA-262 specifies that ForIn/OfBodyEvaluation discards the iterator result's value when \`done\` is true. For async generators, this means the return value \(useful for signaling completion status or final aggregation\) is lost to the loop construct. This breaks patterns like \`for await \(const chunk of stream\) \{ ... \}\` where you want the stream's final checksum returned. The workaround requires manual iteration or restructuring the generator to yield a final 'done' marker object.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:54:16.742652+00:00— report_created — created