use std::time::Duration;
use memberlist_core::{transport::Id, CheapClone};
use crate::types::Member;
#[auto_impl::auto_impl(Box, Arc)]
pub trait ReconnectDelegate: Send + Sync + 'static {
type Id: Id;
type Address: CheapClone + Send + Sync + 'static;
fn reconnect_timeout(
&self,
member: &Member<Self::Id, Self::Address>,
timeout: Duration,
) -> Duration;
}
#[derive(Debug)]
pub struct NoopReconnectDelegate<I, A>(std::marker::PhantomData<(I, A)>);
impl<I, A> Default for NoopReconnectDelegate<I, A> {
fn default() -> Self {
Self(Default::default())
}
}
impl<I, A> Clone for NoopReconnectDelegate<I, A> {
fn clone(&self) -> Self {
*self
}
}
impl<I, A> Copy for NoopReconnectDelegate<I, A> {}
impl<I, A> ReconnectDelegate for NoopReconnectDelegate<I, A>
where
I: Id,
A: CheapClone + Send + Sync + 'static,
{
type Id = I;
type Address = A;
fn reconnect_timeout(
&self,
_member: &Member<Self::Id, Self::Address>,
timeout: Duration,
) -> Duration {
timeout
}
}