Skip to content

fix: Handle non-awaited async generator#4417

Merged
evanw merged 2 commits intoevanw:mainfrom
2767mr:fix/async-generator
Apr 1, 2026
Merged

fix: Handle non-awaited async generator#4417
evanw merged 2 commits intoevanw:mainfrom
2767mr:fix/async-generator

Conversation

@2767mr
Copy link
Copy Markdown
Contributor

@2767mr 2767mr commented Mar 14, 2026

Add a queue to __asyncGenerator to preserve the order in which .next and other generator methods are called even when they are not awaited.

Fixes #4401.

Revert "fix: Call generator functions synchronously if necessary"

This reverts commit b90ba12.
@2767mr 2767mr force-pushed the fix/async-generator branch from b90ba12 to 3afa519 Compare March 14, 2026 11:21
Copy link
Copy Markdown
Owner

@evanw evanw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Really appreciate you adding all of these tests. I see how the queue works and I think this approach makes sense, as TypeScript's __asyncGenerator helper function also uses a queue.

I don't have this loaded in my head right now but I think moving forward is reasonable given the test coverage, the simplicity of the change, and the similarity to TypeScript's approach.

Comment thread internal/runtime/runtime.go
@evanw evanw merged commit a8f8c0e into evanw:main Apr 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception in downleveled code when concurrently polling an async generator that wraps another generator

2 participants