1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Async signal handling.
//!
//! This module lets runtime tasks wait for process signals without blocking the
//! thread-local event loop. [`ctrl_c`] is the portable entry point for shutdown
//! handling; the platform submodule (`unix` or `windows`) exposes streams for
//! specific event kinds, such as terminal resize notifications on Unix or
//! console close events on Windows.
//!
//! POSIX signals are process-global, while this runtime is thread-local and
//! supports `!Send` futures. The Unix backend therefore uses one process-wide
//! async-signal-safe handler plus a dedicated blocking-pool reader task. The
//! handler records a pending bit and wakes a self-pipe/eventfd; the reader task
//! drains that fd and forwards signal notifications as per-thread macrotasks
//! with [`crate::ThreadHandle::queue_macrotask`].
//!
//! This is different from Tokio's default multi-threaded scheduler and
//! async-std: runite cannot freely move `!Send` signal streams between worker
//! threads, so delivery fans out to the runtime threads that registered local
//! streams. Delivery is best-effort. Closed runtime threads are skipped, and a
//! wake for a live thread can be dropped if its macrotask queue is full.
//!
//! # Examples
//!
//! ```no_run
//! use std::cell::Cell;
//! use std::rc::Rc;
//!
//! let shutting_down = Rc::new(Cell::new(false));
//!
//! runite::spawn({
//! let shutting_down = Rc::clone(&shutting_down);
//! async move {
//! runite::signal::ctrl_c()
//! .await
//! .expect("Ctrl-C handler should install");
//! shutting_down.set(true);
//! }
//! });
//!
//! runite::run();
//! ```
/// Awaits a single Ctrl-C interrupt request.
///
/// This is the portable shutdown-signal entry point: on Unix it wraps
/// `unix::signal(unix::SignalKind::Interrupt)`, and on Windows it wraps
/// `windows::ctrl_c`. It completes once and then drops its signal stream.
///
/// # Examples
///
/// ```no_run
/// runite::spawn(async {
/// runite::signal::ctrl_c()
/// .await
/// .expect("Ctrl-C handler should install");
/// eprintln!("received shutdown request");
/// });
///
/// runite::run();
/// ```
pub async