pub fn ctrl_close() -> Result<CtrlClose>
Available on Windows and crate feature
signal
only.Expand description
Creates a new listener 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>> {
// A listener of CTRL-CLOSE events.
let mut signal = ctrl_close()?;
// Print whenever a CTRL-CLOSE event is received.
for countdown in (0..3).rev() {
signal.recv().await;
println!("got CTRL-CLOSE. {} more to exit", countdown);
}
Ok(())
}