Skip to content
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

Add broadcast::Sender::closed Future #6649

Open
schmidma opened this issue Jun 19, 2024 · 1 comment · May be fixed by #6685
Open

Add broadcast::Sender::closed Future #6649

schmidma opened this issue Jun 19, 2024 · 1 comment · May be fixed by #6685
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@schmidma
Copy link

schmidma commented Jun 19, 2024

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

I'm always frustrated when I need to determine if all receivers of a broadcast sender are dropped. Currently, the only way to know if all receivers are gone is by either sending to the channel and getting an error, or by checking the number of receivers. However, there is no way to wait for the event of all receivers being dropped, which would enable a sender to end its operation early if no receivers are interested anymore. This feature is already available in the mpsc and oneshot variants of Tokio channels.

Describe the solution you'd like

I would like the broadcast sender to have a closed future. This future would enable the sender to wait for the event when all receivers are dropped. This way, the sender can stop its operation as soon as there are no more receivers interested in its results.

Describe alternatives you've considered

An alternative solution would be continuously checking the number of receivers or attempting to send a message and catching the error if all receivers are closed. However, this approach is inefficient and explicitly waiting for the close event is not possible.

Additional context

Adding this feature will make the broadcast sender more consistent with the mpsc and oneshot channels, improving its usability in scenarios where the sender needs to know when there are no more receivers.
Related: #2800

@schmidma schmidma added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jun 19, 2024
@Darksonn Darksonn added the M-sync Module: tokio/sync label Jun 19, 2024
@evanrittenhouse
Copy link
Contributor

I can pick this up

@Darksonn Darksonn linked a pull request Jul 14, 2024 that will close this issue
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. M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants