pub struct ShutdownMonitor { /* private fields */ }Expand description
A ShutdownMonitor listens for the shutdown signal from a ShutdownController and
tracks that the signal has been received.
Callers may query for whether the shutdown signal has been received or not.
§Examples
use shutdown_async::ShutdownMonitor;
async fn run(monitor: &mut ShutdownMonitor) {
while !monitor.is_shutdown() {
tokio::select! {
_ = monitor.recv() => { println!("shutdown initiated"); }
_ = async { /* do work */ } => { println!("one year has passed!"); }
}
}
}Implementations§
Source§impl ShutdownMonitor
impl ShutdownMonitor
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Returns true if the shutdown signal has been received, and false otherwise.
§Examples
#[tokio::main]
async fn main() {
let shutdown = shutdown_async::ShutdownController::new();
let mut monitor = shutdown.subscribe();
// Assert that the monitor has not yet received the shutdown signal
assert!(!monitor.is_shutdown());
}Auto Trait Implementations§
impl Freeze for ShutdownMonitor
impl RefUnwindSafe for ShutdownMonitor
impl Send for ShutdownMonitor
impl Sync for ShutdownMonitor
impl Unpin for ShutdownMonitor
impl UnsafeUnpin for ShutdownMonitor
impl UnwindSafe for ShutdownMonitor
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