Struct tokio_utils::ShutdownMonitor
source · 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());
}