Skip to content

refactor(ai): use Promise.withResolvers in EventStream iterator#3333

Open
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:refactor/event-stream-with-resolvers
Open

refactor(ai): use Promise.withResolvers in EventStream iterator#3333
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:refactor/event-stream-with-resolvers

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Summary

Replaces new Promise<IteratorResult<T>>((resolve, reject) => this.waiting.push({ resolve, reject })) with Promise.withResolvers<T>() in EventStream's async iterator, per the project convention in AGENTS.md.

The Promise executor only pushed { resolve, reject } to this.waiting — exactly the pattern Promise.withResolvers() was designed for.

Verification

  • bun check passes
  • 37 tests pass across event-stream.test.ts, agent.test.ts, yield.test.ts, proxy-stream-disconnect.test.ts

Replace new Promise((resolve, reject) => ...) with
Promise.withResolvers() in EventStream's async iterator, per the
project convention in AGENTS.md.
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026
@roboomp roboomp added refactor review:p0 sdk SDK and extension integration surface triaged labels Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor review:p0 sdk SDK and extension integration surface triaged vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants