pub fn ctrl_c() -> Result<CtrlC>
Available on Windows and crate feature
signal
only.Expand description
Creates a new stream which receives “ctrl-c” notifications sent to the process.
Examples
use tokio::signal::windows::ctrl_c;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// An infinite stream of CTRL-C events.
let mut stream = ctrl_c()?;
// Print whenever a CTRL-C event is received.
for countdown in (0..3).rev() {
stream.recv().await;
println!("got CTRL-C. {} more to exit", countdown);
}
Ok(())
}