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