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