sync: add same_channel method to watch::Receiver #4579
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.
I'd like to determine if two
watch::Receiver
s are part of the same channel (i.e. will receive values from the samewatch::Sender
.Specifically, I'd like to have a
HashMap<K, watch::Receiver<V>>
, and then later be able to check if my entry is still there, or someone else has removed it (and potentially replaced it with a Receiver for a different Sender).Describe the solution you'd like
Add a method similar to:
Describe alternatives you've considered
The solution I have today is to use a
HashMap<K, Arc<watch::Sender<V>>
and then useArc::ptr_eq()
to check if the Sender is mine. The disadvantage is that there's an additional heap allocation/indirection for the Arc, and I need to ensure that no extraneous clones of the Arc are created.Additional context
I noticed that @zh-jq opened #3532 to add
mpsc::Sender::same_channel()
and @Darksonn reviewed it. This is similar functionality.I'd be willing to try to implement/upstream this, if it's likely to be accepted.
The text was updated successfully, but these errors were encountered: