mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
signal: add example with background listener (#4171)
This commit is contained in:
@@ -47,6 +47,15 @@ use std::io;
|
|||||||
/// println!("received ctrl-c event");
|
/// 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<()> {
|
pub async fn ctrl_c() -> io::Result<()> {
|
||||||
os_impl::ctrl_c()?.recv().await;
|
os_impl::ctrl_c()?.recv().await;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user