use futures::executor;
use mcu::wait_for_interrupt;
use thread::notify::nop::NOTIFY_NOP;
pub trait PFuture: Future {
fn wait(self) -> Result<Self::Item, Self::Error>;
}
impl<T: Future> PFuture for T {
fn wait(self) -> Result<Self::Item, Self::Error> {
let mut executor = executor::spawn(self);
loop {
match executor.poll_future_notify(&NOTIFY_NOP, 0) {
Ok(Async::NotReady) => wait_for_interrupt(),
Ok(Async::Ready(value)) => break Ok(value),
Err(err) => break Err(err),
}
}
}
}