use crate::Error;
use std::time::Duration;
#[cfg(feature = "sqlite")]
pub mod replica;
#[cfg(feature = "postgres")]
pub mod server;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Backoff {
pub first: Duration,
pub max: Duration,
}
impl Backoff {
#[must_use]
pub const fn new(first: Duration, max: Duration) -> Self {
Backoff { first, max }
}
pub(crate) fn check(&self, what: &str) -> Result<(), Error> {
if self.first.is_zero() || self.first > self.max {
return Err(Error::Misuse(format!(
"`{what}` waits {:?} first and {:?} at most: the first wait is not zero, \
and not longer than the longest",
self.first, self.max
)));
}
Ok(())
}
pub(crate) fn after(&self, wait: Duration) -> Duration {
wait.saturating_mul(2).min(self.max)
}
}