tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.59k stars 2.45k forks source link

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

Closed barafael closed 3 months ago

barafael commented 3 months ago

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.

Darksonn commented 3 months ago

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

Rustin170506 commented 3 months ago

I will try to add it!