1use std::time::{Duration, SystemTime};
2
3use crate::Member;
4
5pub trait DowningProvider: Send + Sync + 'static {
11 fn name(&self) -> &'static str;
13
14 fn should_down(&self, member: &Member, unreachable_for: Duration, now: SystemTime) -> bool;
16}
17
18#[derive(Debug, Clone)]
20pub struct TimeoutDowning {
21 timeout: Duration,
22}
23
24impl TimeoutDowning {
25 #[must_use]
27 pub const fn new(timeout: Duration) -> Self {
28 Self { timeout }
29 }
30
31 #[must_use]
33 pub const fn timeout(&self) -> Duration {
34 self.timeout
35 }
36}
37
38impl DowningProvider for TimeoutDowning {
39 fn name(&self) -> &'static str {
40 "timeout"
41 }
42
43 fn should_down(&self, _member: &Member, unreachable_for: Duration, _now: SystemTime) -> bool {
44 unreachable_for >= self.timeout
45 }
46}