Skip to main content

LocalWaker

Struct LocalWaker 

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

An owned wake handle that can only be used on the thread that acquired it.

Native ntex task wakers acquired on their registered owner thread use local operations without repeating the thread check or registry lookup. Other wakers retain their standard behavior, including wakers from Tokio, Compio, and custom wrappers.

Cloning this handle clones wake ownership; it does not create an empty notification slot. Waking consumes the handle, while wake_by_ref retains it. A handle remains valid after its task completes or its runtime is dropped. Use into_waker to transfer it to another thread as a standard, thread-safe Waker.

On 64-bit targets both this type and Option<LocalWaker> occupy 16 bytes. There is no additional wrapper allocation; a foreign waker’s own clone operation may allocate.

use ntex_rt::LocalWaker;
use std::task::Waker;

let local = LocalWaker::from_waker(Waker::noop());
local.wake_by_ref();
let waker = local.into_waker();
std::thread::spawn(move || waker.wake()).join().unwrap();
ⓘ
fn assert_send<T: Send>() {}
assert_send::<ntex_rt::LocalWaker>();
ⓘ
fn assert_sync<T: Sync>() {}
assert_sync::<ntex_rt::LocalWaker>();

Implementations§

Source§

impl LocalWaker

Source

pub fn from_waker(waker: &Waker) -> Self

Clones a standard waker into a thread-confined wake handle.

Source

pub fn wake(self)

Wakes the associated task, consuming this handle.

Source

pub fn wake_by_ref(&self)

Wakes the associated task without consuming this handle.

Source

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

Returns whether this handle and waker wake the same task.

Like Waker::will_wake, true guarantees the same task, but false may be returned for different representations of the same task.

Source

pub fn into_waker(self) -> Waker

Consumes this handle to produce a thread-safe standard waker.

Native conversion acquires standard-waker ownership before releasing the local reference.

Trait Implementations§

Source§

impl Clone for LocalWaker

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
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 Drop for LocalWaker

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<Waker> for LocalWaker

Source§

fn from(waker: Waker) -> Self

Consumes a standard waker to acquire thread-confined wake ownership.

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