1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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),
}
}
}
}