pub struct Notify<T> { /* private fields */ }
Expand description
A wrapper which wakes tasks on mutable accesses to the wrapped value.
This can be used to transparently notify an asyncronous task that it should, for example, check for more work in a queue or try again to acquire a lock.
Importantly: only DerefMut is used to wake the target task. Read-only access is possible without causing wake events. If no Waker has been registered yet, no task will be woken.
Implementations§
Source§impl<T> Notify<T>
impl<T> Notify<T>
pub fn new(inner: T) -> Self
Sourcepub fn has_waker(ptr: &Notify<T>) -> bool
pub fn has_waker(ptr: &Notify<T>) -> bool
Check whether or not this Notify
has a registered Waker
.
This function is implemented as an associated function rather than a
method to avoid conflicts with methods on the wrapped type.
Call it as Notify::has_waker()
.
Sourcepub fn waker(ptr: &mut Notify<T>) -> Option<Waker>
pub fn waker(ptr: &mut Notify<T>) -> Option<Waker>
Get a copy of the registered Waker
for this Notify
.
This function is implemented as an associated function rather than a
method to avoid conflicts with methods on the wrapped type.
Call it as Notify::waker()
.
Sourcepub fn register_waker(ptr: &mut Notify<T>, waker: &Waker)
pub fn register_waker(ptr: &mut Notify<T>, waker: &Waker)
Register a Waker
to be woken upon mutable accesses to the wrapped value.
This function is implemented as an associated function rather than a
method to avoid conflicts with methods on the wrapped type.
Call it as Notify::register_waker()
.
§Panics
Panics if there is an already registered Waker
.
Use Notify::has_waker
to check the state before using this.
Sourcepub fn clear_waker(ptr: &mut Notify<T>) -> Option<Waker>
pub fn clear_waker(ptr: &mut Notify<T>) -> Option<Waker>
Removes and returns the Waker
registered to this Notify
.
This function is implemented as an associated function rather than a
method to avoid conflicts with methods on the wrapped type.
Call it as Notify::clear_waker()
.
Sourcepub fn into_inner(ptr: Notify<T>) -> T
pub fn into_inner(ptr: Notify<T>) -> T
Consumes the Notify
, dropping any associated Waker
and
returning the inner value without notifying the Waker
.
This function is implemented as an associated function rather than a
method to avoid conflicts with methods on the wrapped type.
Call it as Notify::into_inner()
.