tokio::signal::windows

Function ctrl_shutdown

Source
pub fn ctrl_shutdown() -> Result<CtrlShutdown>
Available on Windows and crate feature signal only.
Expand description

Creates a new listener which receives “ctrl-shutdown” notifications sent to the process.

§Examples

use tokio::signal::windows::ctrl_shutdown;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // A listener of CTRL-SHUTDOWN events.
    let mut signal = ctrl_shutdown()?;

    signal.recv().await;
    println!("got CTRL-SHUTDOWN. Cleaning up before exiting");

    Ok(())
}