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 mpsc::Sender strong and weak counts, similar to Arc counts #5880

Closed
vasilakisfil opened this issue Jul 18, 2023 · 1 comment · Fixed by #6405
Closed

Add mpsc::Sender strong and weak counts, similar to Arc counts #5880

vasilakisfil opened this issue Jul 18, 2023 · 1 comment · Fixed by #6405
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@vasilakisfil
Copy link

Is your feature request related to a problem? Please describe.
The tokio actor pattern described in @Darksonn's blog post is very useful and pervasive. With #4023 we also have WeakSender, automatically making Sender a "strong" Sender. But if we have strong and weak senders, shouldn't we also expose the relevant counts as well?

Describe the solution you'd like
Just how Arc does with strong and weak counts, tokio's mpsc::Sender should expose similar counts.

Describe alternatives you've considered
We could probably wrap these types using newtype pattern, implement our custom clone and achieve the same result, if we desperately needed that. But it would be nice if official API offered these counts

Additional context
We have extended Alice's initial actor pattern with automatic actor termination when all relevant handles get dropped, graceful shutdown and on some actors even, we provide "weak" handles, implemented on top of mpsc::WeakSender, offering similar functionality (doesn't prevent the actor to get dropped even if there are such "weak" handles around). It would be really helpful to have the counts as we could provide better API guarantees on graceful shutdown. Specifically, we wouldn't allow gracefully terminating an actor, even if a handle requests that, if other "strong" handles still exist.

@vasilakisfil vasilakisfil added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jul 18, 2023
@vasilakisfil vasilakisfil changed the title Add mpsc::Sender strong and weak counts, similar to Arc counts Add mpsc::Sender strong and weak counts, similar to Arc counts Jul 18, 2023
@Darksonn Darksonn added the M-sync Module: tokio/sync label Oct 1, 2023
@Darksonn
Copy link
Contributor

Darksonn commented Oct 1, 2023

I'm not opposed to adding this.

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.

2 participants