signal: add example with background listener (#4171)

This commit is contained in:
Jonathan 2021-10-17 20:37:15 +02:00 committed by GitHub
parent d4848a9e2e
commit b5c1fb4012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(())