pub struct HeartbeatWatcher { /* private fields */ }Expand description
Watches heartbeats and detects staleness for idle timeout detection
The watcher receives heartbeat signals from a paired Heartbeat
sender. Call is_alive to check whether a
heartbeat was received within the specified idle timeout duration.
§Examples
ⓘ
use juncture_core::Heartbeat;
use std::time::Duration;
let (heartbeat, mut watcher) = Heartbeat::new_pair();
// Immediately after creation, the watcher considers the source alive
assert!(watcher.is_alive(Duration::from_secs(60)));
// After sending a heartbeat and checking with a short timeout
heartbeat.ping().unwrap();
assert!(watcher.is_alive(Duration::from_secs(10)));Implementations§
Source§impl HeartbeatWatcher
impl HeartbeatWatcher
Sourcepub fn new(rx: UnboundedReceiver<()>) -> Self
pub fn new(rx: UnboundedReceiver<()>) -> Self
Create a new heartbeat watcher from an unbounded receiver
Sourcepub fn is_alive(&mut self, idle_timeout: Duration) -> bool
pub fn is_alive(&mut self, idle_timeout: Duration) -> bool
Check if the watched heartbeat source is still alive
Drains any pending heartbeat signals and returns true if
at least one heartbeat was received within idle_timeout.
Returns false if no heartbeat was received within the
idle timeout duration.
This is a non-blocking check.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HeartbeatWatcher
impl RefUnwindSafe for HeartbeatWatcher
impl Send for HeartbeatWatcher
impl Sync for HeartbeatWatcher
impl Unpin for HeartbeatWatcher
impl UnsafeUnpin for HeartbeatWatcher
impl UnwindSafe for HeartbeatWatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more