[−][src]Crate wakeful
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(), } } }
Traits
Wake | Zero-cost helper trait that makes it easier to implement wakers. |
Functions
waker_fn | Create a waker from a closure. |