future_utils/
resume_unwind.rs1use std::any::Any;
2use std::panic;
3use futures::{Future, Async};
4use void::Void;
5
6pub struct ResumeUnwind<F> {
8 future: F,
9}
10
11impl<F> ResumeUnwind<F> {
12 pub fn new(future: F) -> ResumeUnwind<F> {
13 ResumeUnwind {
14 future,
15 }
16 }
17}
18
19impl<F> Future for ResumeUnwind<F>
20where
21 F: Future<Error=Box<Any + Send + 'static>>,
22{
23 type Item = F::Item;
24 type Error = Void;
25
26 fn poll(&mut self) -> Result<Async<F::Item>, Void> {
27 match self.future.poll() {
28 Ok(Async::Ready(x)) => Ok(Async::Ready(x)),
29 Ok(Async::NotReady) => Ok(Async::NotReady),
30 Err(e) => panic::resume_unwind(e),
31 }
32 }
33}
34