Skip to content

Add AsyncGenerator support to subscribe() for improved DX#169

Merged
antondalgren merged 1 commit intomainfrom
add-async-generator-subscribe
Nov 12, 2025
Merged

Add AsyncGenerator support to subscribe() for improved DX#169
antondalgren merged 1 commit intomainfrom
add-async-generator-subscribe

Conversation

@antondalgren
Copy link
Copy Markdown
Contributor

Extends queue.subscribe() to support AsyncGenerator-based message consumption via consumer.messages property when no callback is provided.

Benefits:

  • Natural iteration with for await...of loops
  • Automatic consumer cancellation on loop exit
  • Better backpressure control
  • Access to consumer methods (wait, cancel, tag)

Implementation:

  • New AMQPGeneratorConsumer subclass handles generator logic
  • subscribe() overloads: with callback returns AMQPConsumer, without callback returns AMQPGeneratorConsumer
  • consumer.messages property (not method) for cleaner syntax
  • Reuses existing callback infrastructure for message delivery

Fixes #168

🤖 Generated with Claude Code

Extends queue.subscribe() to support AsyncGenerator-based message
consumption via consumer.messages property when no callback is provided.

Benefits:
- Natural iteration with for await...of loops
- Automatic consumer cancellation on loop exit
- Better backpressure control
- Access to consumer methods (wait, cancel, tag)

Implementation:
- New AMQPGeneratorConsumer subclass handles generator logic
- subscribe() overloads: with callback returns AMQPConsumer,
  without callback returns AMQPGeneratorConsumer
- consumer.messages property (not method) for cleaner syntax
- Reuses existing callback infrastructure for message delivery

Fixes #168

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@antondalgren antondalgren force-pushed the add-async-generator-subscribe branch from bd6924b to 6aece30 Compare November 12, 2025 07:54
Copy link
Copy Markdown
Member

@baelter baelter left a comment

Choose a reason for hiding this comment

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

Neat! TIL!

@antondalgren antondalgren merged commit 1913a67 into main Nov 12, 2025
6 checks passed
@antondalgren antondalgren deleted the add-async-generator-subscribe branch November 12, 2025 08:22
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.

Make #subscribe return an AsyncGenerator for better DX

2 participants