refactor(ai): use Promise.withResolvers in EventStream iterator#3333
Open
oldschoola wants to merge 2 commits into
Open
refactor(ai): use Promise.withResolvers in EventStream iterator#3333oldschoola wants to merge 2 commits into
oldschoola wants to merge 2 commits into
Conversation
Replace new Promise((resolve, reject) => ...) with Promise.withResolvers() in EventStream's async iterator, per the project convention in AGENTS.md.
roboomp
reviewed
Jun 23, 2026
roboomp
left a comment
Collaborator
There was a problem hiding this comment.
lgtm — semantic-equivalent swap to Promise.withResolvers<IteratorResult<T>>() at packages/ai/src/utils/event-stream.ts:104-106, matching the AGENTS.md Bun convention. Existing event-stream.test.ts coverage still exercises the iterator wake/resume path. Changelog entry present under ## [Unreleased] / ### Changed. Thanks @oldschoola.
Address review: IteratorResult<T> defaults TReturn to any, so the 'done: true' resolves used 'undefined as any'. Now typed as IteratorResult<T, undefined> throughout — waiting array, withResolvers, and resolve calls use plain 'undefined' without any cast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces
new Promise<IteratorResult<T>>((resolve, reject) => this.waiting.push({ resolve, reject }))withPromise.withResolvers<T>()inEventStream's async iterator, per the project convention in AGENTS.md.The Promise executor only pushed
{ resolve, reject }tothis.waiting— exactly the patternPromise.withResolvers()was designed for.Verification
bun checkpassesevent-stream.test.ts,agent.test.ts,yield.test.ts,proxy-stream-disconnect.test.ts