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
impl LocalWaker
Sourcepub fn from_waker(waker: &Waker) -> Self
pub fn from_waker(waker: &Waker) -> Self
Clones a standard waker into a thread-confined wake handle.
Sourcepub fn wake_by_ref(&self)
pub fn wake_by_ref(&self)
Wakes the associated task without consuming this handle.
Sourcepub fn will_wake(&self, waker: &Waker) -> bool
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.
Sourcepub fn into_waker(self) -> Waker
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.