pub fn ctrl_close() -> Result<CtrlClose>
Available on Windows and crate feature signal only.
Expand description

Creates a new stream which receives “ctrl-close” notifications sent to the process.

Examples

use tokio::signal::windows::ctrl_close;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // An infinite stream of CTRL-CLOSE events.
    let mut stream = ctrl_close()?;

    // Print whenever a CTRL-CLOSE event is received.
    for countdown in (0..3).rev() {
        stream.recv().await;
        println!("got CTRL-CLOSE. {} more to exit", countdown);
    }

    Ok(())
}