Skip to content

Implement merge for async iterables#54

Merged
msullivan merged 3 commits into
mainfrom
interleave
Apr 28, 2026
Merged

Implement merge for async iterables#54
msullivan merged 3 commits into
mainfrom
interleave

Conversation

@msullivan

Copy link
Copy Markdown
Contributor

(Was called interleave in discussions earlier, but @elprans thought
interleave sounded too deterministic.)

@msullivan msullivan requested review from 1st1 and anbuzin April 28, 2026 16:39
@vercel

vercel Bot commented Apr 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
py-ai Ready Ready Preview, Comment Apr 28, 2026 8:02pm

Request Review

Comment thread src/ai/util.py Outdated

# Launch a task doing anext on every iterator
tasks: list[asyncio.Future[T] | None] = [
asyncio.ensure_future(iter.__anext__()) for iter in aiters

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.

Use the anext() / aiter() built-ins

Comment thread src/ai/util.py Outdated
iter = aiters[idx]
tasks[idx] = asyncio.ensure_future(iter.__anext__())
yield t.result()
except Exception:

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.

Use async with TaskGroup() instead of this

(Was called interleave in discussions earlier, but @elprans thought
interleave sounded too deterministic.)
@msullivan msullivan merged commit 82c1424 into main Apr 28, 2026
6 checks passed
@msullivan msullivan deleted the interleave branch April 28, 2026 20:07
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.

3 participants