use super::super::DebouncePolicy;
use super::super::listener::ApiListener;
use super::stream::HybridStream;
use crate::network::AddressFetcher;
use crate::time::{Clock, SystemClock};
use std::time::Duration;
#[derive(Debug)]
pub struct HybridMonitor<F, L, C = SystemClock> {
fetcher: F,
api_listener: L,
clock: C,
poll_interval: Duration,
debounce: Option<DebouncePolicy>,
}
impl<F, L> HybridMonitor<F, L, SystemClock>
where
F: AddressFetcher,
L: ApiListener,
{
#[must_use]
pub const fn new(fetcher: F, api_listener: L, poll_interval: Duration) -> Self {
Self::with_clock(fetcher, api_listener, SystemClock, poll_interval)
}
}
impl<F, L, C> HybridMonitor<F, L, C>
where
F: AddressFetcher,
L: ApiListener,
C: Clock,
{
#[must_use]
pub const fn with_clock(
fetcher: F,
api_listener: L,
clock: C,
poll_interval: Duration,
) -> Self {
Self {
fetcher,
api_listener,
clock,
poll_interval,
debounce: None,
}
}
#[must_use]
pub const fn with_debounce(mut self, policy: DebouncePolicy) -> Self {
self.debounce = Some(policy);
self
}
#[must_use]
pub const fn poll_interval(&self) -> Duration {
self.poll_interval
}
#[must_use]
pub const fn debounce(&self) -> Option<&DebouncePolicy> {
self.debounce.as_ref()
}
#[must_use]
pub fn into_stream(self) -> HybridStream<F, L::Stream, C> {
let api_stream = self.api_listener.into_stream();
HybridStream::new(
self.fetcher,
api_stream,
self.clock,
self.poll_interval,
self.debounce,
)
}
}