[][src]Struct tokio_sync::AtomicWaker

pub struct AtomicWaker { /* fields omitted */ }

A synchronization primitive for task waking.

AtomicWaker will coordinate concurrent wakes with the consumer potentially "waking" the underlying task. This is useful in scenarios where a computation completes in another thread and wants to wake 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 AtomicWaker may be reused for any number of calls to register or wake.

Methods

impl AtomicWaker[src]

pub fn new() -> AtomicWaker[src]

Create an AtomicWaker

pub fn register(&self, waker: Waker)[src]

Registers the current waker to be notified on calls to wake.

This is the same as calling register_task with task::current().

pub fn register_by_ref(&self, waker: &Waker)[src]

Registers the provided waker to be notified on calls to wake.

The new waker will take place of any previous wakers that were registered by previous calls to register. Any calls to wake that happen after a call to register (as defined by the memory ordering rules), will wake the register caller's task.

It is safe to call register with multiple other threads concurrently calling wake. This will result in the register caller's current task being woken once.

This function is safe to call concurrently, but this is generally a bad idea. Concurrent calls to register will attempt to register different tasks to be woken. One of the callers will win and have its task set, but there is no guarantee as to which caller will succeed.

pub fn wake(&self)[src]

Wakes the task that last called register.

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

pub fn take_waker(&self) -> Option<Waker>[src]

Attempts to take the Waker value out of the AtomicWaker with the intention that the caller will wake the task later.

Trait Implementations

impl Send for AtomicWaker[src]

impl Default for AtomicWaker[src]

impl Sync for AtomicWaker[src]

impl Debug for AtomicWaker[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]