pub struct PollingMonitor<F, C = SystemClock> { /* private fields */ }Expand description
Polling-based IP address monitor.
Periodically fetches network adapter information and emits a stream
of super::super::IpChange events when addresses are added or removed.
§Type Parameters
F- TheAddressFetcherimplementation for retrieving adapter snapshotsC- TheClockimplementation for timestamps (defaults toSystemClock)
§Example
use ddns_a::monitor::PollingMonitor;
use ddns_a::time::SystemClock;
use std::time::Duration;
let fetcher = MyFetcher::new();
let monitor = PollingMonitor::new(fetcher, Duration::from_secs(60));
let mut stream = monitor.into_stream();
while let Some(changes) = stream.next().await {
for change in changes {
println!("{:?}", change);
}
}Implementations§
Source§impl<F> PollingMonitor<F, SystemClock>where
F: AddressFetcher,
impl<F> PollingMonitor<F, SystemClock>where
F: AddressFetcher,
Source§impl<F, C> PollingMonitor<F, C>where
F: AddressFetcher,
C: Clock,
impl<F, C> PollingMonitor<F, C>where
F: AddressFetcher,
C: Clock,
Sourcepub const fn with_clock(fetcher: F, clock: C, interval: Duration) -> Self
pub const fn with_clock(fetcher: F, clock: C, interval: Duration) -> Self
Creates a new polling monitor with a custom clock.
This constructor allows injecting a mock clock for testing.
§Arguments
fetcher- The address fetcher to use for pollingclock- The clock to use for timestampsinterval- The interval between polls
Sourcepub const fn with_debounce(self, policy: DebouncePolicy) -> Self
pub const fn with_debounce(self, policy: DebouncePolicy) -> Self
Configures debounce policy for this monitor.
When debounce is enabled, rapid consecutive changes within the debounce window are merged, with cancelling changes (add then remove of the same IP) being eliminated.
§Arguments
policy- The debounce policy to apply
Sourcepub const fn debounce(&self) -> Option<&DebouncePolicy>
pub const fn debounce(&self) -> Option<&DebouncePolicy>
Returns the configured debounce policy, if any.
Sourcepub fn into_stream(self) -> PollingStream<F, C>
pub fn into_stream(self) -> PollingStream<F, C>
Converts this monitor into a stream of IP changes.
The returned stream will poll at the configured interval and
yield batches of super::super::IpChange events whenever addresses change.
The stream never terminates on its own; use take_until with
a shutdown signal to stop it gracefully.