tokio_retry/strategy/
fixed_interval.rs

1use std::iter::Iterator;
2use std::time::Duration;
3
4/// A retry strategy driven by a fixed interval.
5#[derive(Debug, Clone)]
6pub struct FixedInterval {
7    duration: Duration,
8}
9
10impl FixedInterval {
11    /// Constructs a new fixed interval strategy.
12    pub fn new(duration: Duration) -> FixedInterval {
13        FixedInterval { duration: duration }
14    }
15
16    /// Constructs a new fixed interval strategy,
17    /// given a duration in milliseconds.
18    pub fn from_millis(millis: u64) -> FixedInterval {
19        FixedInterval {
20            duration: Duration::from_millis(millis),
21        }
22    }
23}
24
25impl Iterator for FixedInterval {
26    type Item = Duration;
27
28    fn next(&mut self) -> Option<Duration> {
29        Some(self.duration)
30    }
31}
32
33#[test]
34fn returns_some_fixed() {
35    let mut s = FixedInterval::new(Duration::from_millis(123));
36
37    assert_eq!(s.next(), Some(Duration::from_millis(123)));
38    assert_eq!(s.next(), Some(Duration::from_millis(123)));
39    assert_eq!(s.next(), Some(Duration::from_millis(123)));
40}