2 stable releases
1.1.0 | Aug 24, 2024 |
---|---|
1.0.0 | Jul 27, 2024 |
#483 in Asynchronous
32 downloads per month
5KB
thread-waker
Waker implementation using current thread token.
This is useful to work with futures without actually employing runtime
Usage
use core::{time, task};
use std::thread;
use thread_waker::waker;
fn my_future(waker: task::Waker) {
thread::sleep(time::Duration::from_millis(250));
waker.wake();
}
let waker = waker(thread::current());
for _ in 0..4 {
let waker = waker.clone();
thread::spawn(move || my_future(waker));
thread::park();
}
println!("I'm done!");
lib.rs
:
Waker implementation using current thread token.
This is useful to work with futures without actually employing runtime
Usage
use core::{time, task};
use std::thread;
use thread_waker::waker;
fn my_future(waker: task::Waker) {
thread::sleep(time::Duration::from_millis(250));
waker.wake();
}
let waker = waker(thread::current());
for _ in 0..4 {
let waker = waker.clone();
thread::spawn(move || my_future(waker));
thread::park();
}
println!("I'm done!");