use super::{Backoff, spin};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModelBasedBackoff {
spins: &'static [u32],
}
impl ModelBasedBackoff {
#[must_use]
pub const fn new(spins: &'static [u32]) -> Self {
Self { spins }
}
}
impl Backoff for ModelBasedBackoff {
fn backoff(&self, attempt: u32) {
if self.spins.is_empty() {
return;
}
let idx = (attempt.saturating_sub(1) as usize).min(self.spins.len() - 1);
spin(self.spins[idx]);
}
}