Struct shutdown_async::ShutdownController
source · pub struct ShutdownController { /* private fields */ }
Expand description
A ShutdownController
is used to control the shutdown of an application.
This is accomplished by creating a ShutdownMonitor
instance for each task
that should be monitored. When ShutdownController::shutdown
is called,
all ShutdownMonitor
instances will be notified that shutdown has started.
Implementations§
source§impl ShutdownController
impl ShutdownController
sourcepub fn subscribe(&self) -> ShutdownMonitor
pub fn subscribe(&self) -> ShutdownMonitor
Create a new ShutdownMonitor
instance that can listen for the shutdown signal.
Examples
let shutdown = shutdown_async::ShutdownController::new();
let monitor = shutdown.subscribe();
sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Begin shutting down and wait for all ShutdownMonitor
instances to be dropped.
Examples
#[tokio::main]
async fn main() {
let shutdown = shutdown_async::ShutdownController::new();
// ... do stuff ...
shutdown.shutdown().await;
}