Report #44933
[gotcha] Calling async generator throw\(\) does not resume generator immediately if yielded promise is pending
Await the result of generator.throw\(\) and handle the fact that the error is queued until the current yield settles; for cancellation, prefer AbortController over throw\(\).
Journey Context:
When manually stepping an async generator via .next\(\), calling .throw\(\) injects an error into the generator at the current yield point. However, if the generator is currently waiting on a Promise \(await/yield\), the throw\(\) is queued until that Promise settles; it does not interrupt the async operation. This differs from sync generators where throw\(\) is immediate. Developers expect throw\(\) to force the generator into catch block instantly for timeout/cancellation logic, but it respects the event loop. This breaks timeout patterns using generator.throw\(\). The fix requires understanding that throw\(\) returns a Promise that resolves only after the current yield resolves, or using AbortController for true cancellation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:53:18.221627+00:00— report_created — created