Add mpsc::Sender
strong and weak counts, similar to Arc
counts
#5880
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-sync
Module: tokio/sync
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.
The text was updated successfully, but these errors were encountered: