-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide broadcast::Sender::new and watch::Sender::new functions #4958
Comments
Apparently
See also this post on URLO. The other send methods ( |
I was also surprised by this, you can call That's ok for broadcasts where you lose all messages previous to subscribing, implementing something else would be hard considering how it currently works. Regarding |
You can actually send a value without any receivers on a watch channel if you use The |
Reopening since this also applies to the watch channel. |
Is your feature request related to a problem?
I'm planning to create an SDR framework where data is streamed between certain "processing blocks". These blocks can be dynamically connected with each other (and disconnected). I planned to use
broadcast
"channels" for that purpose. However, when I create a producer, I might not have a consumer (yet), so I would only need abroadcast::Sender
. There is currently no way to create aSender
without also creating aReceiver
.A similar situation applies to
tokio::sync::watch
, where it's also not possible to create aSender
without aReceiver
.Describe the solution you'd like
I propose to add the following associated functions
tokio::sync::broadcast::Sender<T>::new(capacity: usize)
tokio::sync::watch::Sender<T>::new(init: T)
which act like
tokio::sync::broadcast::channel::<T>(capacity).0
tokio::sync::watch::channel::<T>(init).0
with the difference that the receiver isn't needlessly created and then dropped.
Describe alternatives you've considered
Using
.0
on the(Sender, Receiver)
pair is a good workaround, but might have unnecessary runtime overhead and is also less readable/verbose. Compare:vs
Additional context
Also note #4957.
The text was updated successfully, but these errors were encountered: