1use crate::sys::{TimeSpec, Timer};
2use futures::{try_ready, Async, Future, Poll};
3use std::io;
4use std::time::Duration;
5
6pub struct Delay {
10 e: Option<Timer>,
11}
12
13impl Delay {
14 #[deprecated(since = "0.1.8", note = "Please use the async-timer crate")]
16 pub fn new(delay: Duration) -> io::Result<Self> {
17 if delay.as_secs() == 0 && delay.subsec_nanos() == 0 {
18 return Ok(Self { e: None });
20 }
21
22 let mut timer = Timer::new()?;
23
24 timer.set(TimeSpec::Timeout(delay))?;
26
27 Ok(Self { e: Some(timer) })
28 }
29}
30
31impl Future for Delay {
32 type Item = ();
33 type Error = io::Error;
34 fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
35 if let Some(ref mut e) = self.e {
36 try_ready!(e.poll());
37 }
38 Ok(Async::Ready(()))
39 }
40}