0.1.1 |
|
---|---|
0.1.0 |
|
#18 in #aid
13KB
153 lines
Wakeful
Utilities to aid implementing Waker
s and working with tasks.
Documentation
Please check out the documentation for details on what Wakeful can do and how to use it.
License
This library is licensed under the MIT license. See the LICENSE file for details.
lib.rs
:
Utilities to aid implementing Waker
s and working with
tasks.
The highlight of this crate is Wake
, which allows you to construct
wakers from your own types by implementing this trait.
Examples
Implementing your own block_on
function using this crate:
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
thread,
};
use wakeful::Wake;
fn block_on<F: Future>(mut future: F) -> F::Output {
let waker = thread::current().into_waker();
let mut context = Context::from_waker(&waker);
let mut future = unsafe { Pin::new_unchecked(&mut future) };
loop {
match future.as_mut().poll(&mut context) {
Poll::Ready(output) => return output,
Poll::Pending => thread::park(),
}
}
}