Skip to main content

LocalWaker

Struct LocalWaker 

Source
pub struct LocalWaker { /* private fields */ }
Expand description

A single-threaded synchronization primitive for task wake-up.

Sometimes the task interested in a given event will change over time. A LocalWaker can coordinate 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.

The slot and its owned local handle must remain on their acquiring thread. Use take to transfer a registered standard waker instead.

ⓘ
fn assert_send<T: Send>() {}
assert_send::<ntex_util::task::LocalWaker>();
ⓘ
fn assert_sync<T: Sync>() {}
assert_sync::<ntex_util::task::LocalWaker>();

Implementations§

Source§

impl LocalWaker

Source

pub fn new() -> Self

Creates an empty LocalWaker.

Source

pub fn with(waker: Option<Waker>) -> Self

Creates a LocalWaker with an optional initial waker.

Source

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

Registers the waker to be notified on calls to wake.

Returns true if a waker was already registered.

If cloning the replacement panics, the previous registration is retained unless the clone callback itself changes the slot.

Source

pub fn wake(&self)

Calls wake on the last Waker passed to register.

The waker is consumed, so a later wake does nothing until register is called again. If no waker is registered, this does nothing.

Source

pub fn wake_checked(&self) -> bool

Calls wake on the last Waker passed to register.

Returns false if no waker is registered. Like wake, this consumes the registered waker.

Source

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

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

This empties the slot and converts the owned handle into a thread-safe standard waker without cloning. If no waker is registered, returns None. Use take_local to retain native local operations.

Source

pub fn take_local(&self) -> Option<LocalWaker>

Takes the registered wake handle, leaving the slot empty.

The returned handle retains native local operations and cannot be sent to another thread. If no waker is registered, returns None.

Trait Implementations§

Source§

impl Clone for LocalWaker

Cloning creates an empty LocalWaker; the registered waker is not copied.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V