Skip to content

Add WeakReceiver to tokio::sync::broadcast #7386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mladedav opened this issue Jun 5, 2025 · 0 comments
Open

Add WeakReceiver to tokio::sync::broadcast #7386

mladedav opened this issue Jun 5, 2025 · 0 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request.

Comments

@mladedav
Copy link

mladedav commented Jun 5, 2025

Is your feature request related to a problem? Please describe.

#7003 has added WeakSender to tokio::sync::broadcast but there is no WeakReceiver.

We have a use-case where we use a broadcast channel to pass around data to consumers while waiting for Sender::close to resolve so that we kill the processing once there is no one interested in any new data.

We now want to add one special consumer that always exists as long as the Sender exists, but we don't want it to prevent the producing task from exiting.

Describe the solution you'd like

Add tokio::sync::broadcast::WeakReceiver that does not count towards RAII, symetrical to WeakSender.

Describe alternatives you've considered

  • To not use Sender::close and instead manually track number of receivers.
  • To use multiple channels, one for "Strong" subscribers, one for "Weak" ones.

Additional context

This could also make sense for watch, the other channels only ever have a single receiver.

@mladedav mladedav added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jun 5, 2025
@mladedav mladedav changed the title Add WeakSender to tokio::sync::broadcast Add WeakReceiver to tokio::sync::broadcast Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request.
Projects
None yet
Development

No branches or pull requests

1 participant