mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
signal: add example with background listener (#4171)
This commit is contained in:
parent
d4848a9e2e
commit
b5c1fb4012
@ -47,6 +47,15 @@ use std::io;
|
||||
/// println!("received ctrl-c event");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Listen in the background:
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// tokio::spawn(async move {
|
||||
/// tokio::signal::ctrl_c().await.unwrap();
|
||||
/// // Your handler here
|
||||
/// });
|
||||
/// ```
|
||||
pub async fn ctrl_c() -> io::Result<()> {
|
||||
os_impl::ctrl_c()?.recv().await;
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user