Struct tokio_shutdown::Broadcaster
source · [−]pub struct Broadcaster<R: Clone = (), A = ()> {
pub(crate) broadcaster: Sender<R>,
pub(crate) shutdown_watcher: UnboundedReceiver<A>,
pub(crate) mpsc_copy: UnboundedSender<A>,
}
Expand description
Allows signalling a shutdown, with a particular reason ShutdownReason<R>
for the shutdown. Also allows for listening to an acknowledgement A
of
the shutdown from the various listeners.
If dropped, a shutdown of type ShutdownReason::BroadcasterClosed
will
occur.
Generics
R
: The reason for initiating the shutdown. Can be helpful when there are multiple causes of a shutdown, and the listeners will clean up differently depending on the shutdown reason.A
: An acknowledgement of the shutdown, possibly containing any useful information that can be sent back to theShutdownBroadcaster
.
Fields
broadcaster: Sender<R>
shutdown_watcher: UnboundedReceiver<A>
mpsc_copy: UnboundedSender<A>
Implementations
sourceimpl<R: Clone, A> Broadcaster<R, A>
impl<R: Clone, A> Broadcaster<R, A>
pub fn new() -> Self
sourcepub fn new_listener(&self) -> Listener<R, A>
pub fn new_listener(&self) -> Listener<R, A>
Creates a new Listener
to the Broadcaster
.
pub fn num_listeners(&self) -> usize
sourcepub fn signal_shutdown(self, reason: Option<R>) -> UnboundedReceiver<A>
pub fn signal_shutdown(self, reason: Option<R>) -> UnboundedReceiver<A>
Signals shutdown, with an optional reason. If no reason is provided, the
listeners will get ShutdownReason::BroadcasterClosed
.
Returns
Returns a channel to be used for receiving the shutdown acknowledgements.
Trait Implementations
Auto Trait Implementations
impl<R = (), A = ()> !RefUnwindSafe for Broadcaster<R, A>
impl<R, A> Send for Broadcaster<R, A>where
A: Send,
R: Send,
impl<R, A> Sync for Broadcaster<R, A>where
A: Send,
R: Send,
impl<R, A> Unpin for Broadcaster<R, A>
impl<R = (), A = ()> !UnwindSafe for Broadcaster<R, A>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more