Permit sending into a watch::Sender
without active Receiver
s
#4165
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.
Relates to #3757. The newly-public
subscribe()
function works very nicely for allowing consumers to monitor a value which is being maintained elsewhere. (Thank you!) There is a rough edge, however, that it can "recover" from a receiver-less situation automatically, but you are unable to introduce new values in the meantime.(Playground)
The code sending new values into the channel is probably not closely aware of the coming-and-going of subscribers. In a use-case where it is expected that the receiver count will sometimes drop to 0, it complicates the sending code that you will get an
Err
result at arbitrary times.Describe the solution you'd like
Sending into a watch channel with no receivers will succeed, becoming the most-recent (already seen) value for any new subscribers.
Describe alternatives you've considered
It is possible to work around this, provided the code that is issuing calls to
send()
and the code that is creating new subscribers both share exclusive/mutable access to thewatch::Sender
.Additional context
This request feels a little selfish—hypothetically I can think of use cases where you really do want your sender to error when nobody is interested in the value any more. I don't have any of those use cases today. I'm not sure if these two different use cases should even be served by the same type.
I'm not going to strongly advocate for the solution presented above. Mostly I want to highlight that it feels slightly awkward right now, and maybe there is a better way to iterate on it?
The text was updated successfully, but these errors were encountered: