future_utils/
delay.rs

1//! tokio timeouts cannot actually error, but for some stupid reason tokio decided to put an io
2//! error on them. This is just a wrapper which removes the error and makes error handling easier
3//! when using timeouts.
4
5use futures::{Async, Future};
6use std::time::Instant;
7use void::Void;
8use tokio;
9
10pub struct Delay {
11    inner: tokio::timer::Delay,
12}
13
14impl Delay {
15    pub fn new(at: Instant) -> Delay {
16        Delay {
17            inner: tokio::timer::Delay::new(at),
18        }
19    }
20
21    pub fn reset(&mut self, at: Instant) {
22        self.inner.reset(at)
23    }
24}
25
26impl Future for Delay {
27    type Item = ();
28    type Error = Void;
29
30    fn poll(&mut self) -> Result<Async<()>, Void> {
31        Ok(unwrap!(self.inner.poll()))
32    }
33}
34