pub(crate) struct OneshotNotifier<T = ()> {
context: &'static str,
sender: Arc<Mutex<Option<Sender<T>>>>,
}Expand description
A helper type to wait for a notification that can occur only one time.
OneshotNotifier::listen() must be called to initialize it and get a
receiver. The receiver must then be .awaited and the future will resolve
when it is notified.
The receiver will receive a signal the first time that
OneshotNotifier::notify_value() is called. Further calls to this
function will be noops until a new receiver is created.The value to return
must implement Default, as this is the value that will be sent to the
receiver when the notifier is dropped before a value is notified.
This notifier can be cloned freely and moved between threads.
It is also possible to share this notifier between tasks to make sure that a
single task is running at a time. If OneshotNotifier::listen() is called
while there is already a receiver waiting, it will be notified as if the
notifier was dropped.
Fields§
§context: &'static strThe context used to identify the notifier in logs.
sender: Arc<Mutex<Option<Sender<T>>>>The sender for the notification signal.
Implementations§
Source§impl<T> OneshotNotifier<T>
impl<T> OneshotNotifier<T>
Source§impl<T> OneshotNotifier<T>
impl<T> OneshotNotifier<T>
Sourcepub(crate) fn listen(&self) -> OneshotNotifierReceiver<T>
pub(crate) fn listen(&self) -> OneshotNotifierReceiver<T>
Initialize this OneshotNotifier and get a receiver.
Sourcepub(crate) fn notify_value(&self, value: T)
pub(crate) fn notify_value(&self, value: T)
Notify the receiver with the given value, if any receiver is still listening.
Trait Implementations§
Source§impl<T: Clone> Clone for OneshotNotifier<T>
impl<T: Clone> Clone for OneshotNotifier<T>
Source§fn clone(&self) -> OneshotNotifier<T>
fn clone(&self) -> OneshotNotifier<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for OneshotNotifier<T>
impl<T> RefUnwindSafe for OneshotNotifier<T>
impl<T> Send for OneshotNotifier<T>where
T: Send,
impl<T> Sync for OneshotNotifier<T>where
T: Send,
impl<T> Unpin for OneshotNotifier<T>
impl<T> UnsafeUnpin for OneshotNotifier<T>
impl<T> UnwindSafe for OneshotNotifier<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more