compio_signal/
lib.rs

1//! Asynchronous signal handling.
2//!
3//! # Examples
4//!
5//! Print on "ctrl-c" notification.
6//!
7//! ```rust,no_run
8//! use compio_signal::ctrl_c;
9//!
10//! # compio_runtime::Runtime::new().unwrap().block_on(async {
11//! ctrl_c().await.unwrap();
12//! println!("ctrl-c received!");
13//! # })
14//! ```
15
16#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
17#![cfg_attr(feature = "once_cell_try", feature(once_cell_try))]
18#![cfg_attr(feature = "lazy_cell", feature(lazy_cell))]
19#![warn(missing_docs)]
20#![allow(stable_features)]
21
22#[cfg(windows)]
23pub mod windows;
24
25#[cfg(unix)]
26#[cfg_attr(target_os = "linux", path = "linux.rs")]
27pub mod unix;
28
29/// Completes when a "ctrl-c" notification is sent to the process.
30pub async fn ctrl_c() -> std::io::Result<()> {
31    #[cfg(windows)]
32    {
33        windows::ctrl_c().await
34    }
35    #[cfg(unix)]
36    {
37        unix::signal(libc::SIGINT).await
38    }
39}