use super::jitter::jitter_spins;
use super::{Backoff, spin};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConstantBackoff {
spins: u32,
#[cfg(feature = "rand")]
jitter: Option<u32>, #[cfg(not(feature = "rand"))]
jitter: Option<(u64, u32)>, }
impl ConstantBackoff {
#[cfg(feature = "rand")]
#[must_use]
pub const fn new(spins: u32, jitter: Option<u32>) -> Self {
Self { spins, jitter }
}
#[cfg(not(feature = "rand"))]
#[must_use]
pub const fn new(spins: u32, jitter: Option<(u64, u32)>) -> Self {
Self { spins, jitter }
}
}
impl Backoff for ConstantBackoff {
fn backoff(&self, attempt: u32) {
spin(
self.spins
.saturating_add(jitter_spins(self.jitter, attempt)),
);
}
}