Function waker_fn::waker_fn

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

Converts a closure into a Waker.

The closure gets called every time the waker is woken.

§Examples

use waker_fn::waker_fn;

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

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