Struct local_waker::LocalWaker

source ·
pub struct LocalWaker { /* private fields */ }
Expand description

A synchronization primitive for task wakeup.

Sometimes the task interested in a given event will change over time. A LocalWaker can coordinate concurrent notifications with the consumer, potentially “updating” the underlying task to wake up. This is useful in scenarios where a computation completes in another task and wants to notify the consumer, but the consumer is in the process of being migrated to a new logical task.

Consumers should call register before checking the result of a computation and producers should call wake after producing the computation (this differs from the usual thread::park pattern). It is also permitted for wake to be called before register. This results in a no-op.

A single LocalWaker may be reused for any number of calls to register or wake.

Implementations§

source§

impl LocalWaker

source

pub fn new() -> Self

Creates a new, empty LocalWaker.

source

pub fn register(&self, waker: &Waker) -> bool

Registers the waker to be notified on calls to wake.

Returns true if waker was registered before.

source

pub fn wake(&self)

Calls wake on the last Waker passed to register.

If register has not been called yet, then this does nothing.

source

pub fn take(&self) -> Option<Waker>

Returns the last Waker passed to register, so that the user can wake it.

If a waker has not been registered, this returns None.

Trait Implementations§

source§

impl Debug for LocalWaker

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for LocalWaker

source§

fn default() -> LocalWaker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.