use std::time::{Duration, SystemTime};
use crate::Member;
pub trait DowningProvider: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn should_down(&self, member: &Member, unreachable_for: Duration, now: SystemTime) -> bool;
}
#[derive(Debug, Clone)]
pub struct TimeoutDowning {
timeout: Duration,
}
impl TimeoutDowning {
#[must_use]
pub const fn new(timeout: Duration) -> Self {
Self { timeout }
}
#[must_use]
pub const fn timeout(&self) -> Duration {
self.timeout
}
}
impl DowningProvider for TimeoutDowning {
fn name(&self) -> &'static str {
"timeout"
}
fn should_down(&self, _member: &Member, unreachable_for: Duration, _now: SystemTime) -> bool {
unreachable_for >= self.timeout
}
}