1
//! Detect a "ctrl-c" notification or other reason to exit.
2

            
3
use crate::Result;
4

            
5
/// Wait until a control-c notification is received, using an appropriate
6
/// runtime mechanism.
7
///
8
/// This function can have pretty kludgy side-effects: see
9
/// documentation for `tokio::signal::ctrl_c` and `async_ctrlc` for
10
/// caveats.  Notably, you can only call this once with async_std.
11
pub async fn wait_for_ctrl_c() -> Result<()> {
12
    #[cfg(feature = "tokio")]
13
    {
14
        tokio_crate::signal::ctrl_c().await?;
15
    }
16
    #[cfg(all(feature = "async-std", not(feature = "tokio")))]
17
    {
18
        async_ctrlc::CtrlC::new().unwrap().await;
19
    }
20
    Ok(())
21
}