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
#[cfg_attr(feature = "experimental-api", visibility::make(pub))]
12
pub(crate) async fn wait_for_ctrl_c() -> Result<()> {
13
    #[cfg(feature = "tokio")]
14
    {
15
        tokio_crate::signal::ctrl_c().await?;
16
    }
17
    #[cfg(all(feature = "async-std", not(feature = "tokio")))]
18
    {
19
        async_ctrlc::CtrlC::new().unwrap().await;
20
    }
21
    Ok(())
22
}