Skip to main content

internetarchive_rs/
poll.rs

1//! Polling configuration used by high-level workflow helpers.
2
3use std::time::Duration;
4
5/// Exponential-backoff settings for polling Internet Archive state changes.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct PollOptions {
8    /// Maximum total time spent polling.
9    pub max_wait: Duration,
10    /// First delay between attempts.
11    pub initial_delay: Duration,
12    /// Maximum delay between attempts.
13    pub max_delay: Duration,
14}
15
16impl Default for PollOptions {
17    fn default() -> Self {
18        Self {
19            max_wait: Duration::from_secs(120),
20            initial_delay: Duration::from_millis(500),
21            max_delay: Duration::from_secs(5),
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::PollOptions;
29    use std::time::Duration;
30
31    #[test]
32    fn defaults_allow_for_archive_eventual_consistency() {
33        let poll = PollOptions::default();
34        assert_eq!(poll.max_wait, Duration::from_secs(120));
35        assert_eq!(poll.initial_delay, Duration::from_millis(500));
36        assert_eq!(poll.max_delay, Duration::from_secs(5));
37    }
38}