Skip to main content

## waker_fn

# Function waker_fn

Source

    pub fn waker_fn<F: Fn() + Send + Sync + 'static>(f: F) -> Waker

🔬This is a nightly-only experimental API. (`waker_fn` #149580)
Expand description

Converts a closure into a `Waker`.

The closure gets called every time the waker is woken.

## §Examples

    #![feature(waker_fn)]
    use std::task::waker_fn;

    let waker = waker_fn(|| println!("woken"));

    waker.wake_by_ref(); // Prints "woken".
    waker.wake();        // Prints "woken".