tokio icon indicating copy to clipboard operation
tokio copied to clipboard

Get `mpsc::Sender` count on `mpsc::Receiver`

Open barafael opened this issue 1 year ago • 2 comments

Context

I frequently work on designs where an mpsc channel "holds the app together", for example a simple TCP server that connects multiple clients with a shared resource. When I want to see how my system performs (under load etc.) I can already see many things like the number of enqueued messages.

In some cases, I also want to see the Number of existing Senders for a receiver.

Solution

I'd love it if one could call a method on mpsc::Receiver to get the number of mpsc::Senders.

Alternative

Arc<AtomicUsize> shared by senders? The advantage is that senders could see the sender count too, for whatever use.

barafael avatar Jun 24 '24 11:06 barafael

We already have weak_count and strong_count methods on Sender. I think it makes sense to add them to the Receiver as well.

Darksonn avatar Jun 24 '24 11:06 Darksonn

I will try to add it!

0xPoe avatar Jun 24 '24 14:06 0xPoe