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
//! Ctrl-C handling, which is the one place this CLI is platform code.
//!
//! Its own module because it is the only thing here that differs between
//! Unix and Windows, and because `main.rs` should read as argument parsing
//! and printing — which is what it claims to be.
/// A Ctrl-C listener that outlives `park`.
///
/// tokio installs its handler on first use and documents that it stays
/// installed for the life of the process — "even if this `Signal` instance
/// is dropped, subsequent SIGINT deliveries will end up captured by Tokio,
/// and the default platform behavior will NOT be reset". So a `park` that
/// created its own listener and returned left every later Ctrl-C going
/// nowhere: the first one entered `shutdown`, and if that took a while the
/// operator's only remaining option was `kill` from another terminal.
/// Keeping one listener alive across both phases is what makes the second
/// interrupt mean something.
///
/// The two platform types are the same idea under different names — a
/// stream that yields once per interrupt — which is why the whole
/// difference fits in the field and the constructor. What is *not*
/// interchangeable is `tokio::signal::ctrl_c()`: it is a one-shot future,
/// and the second Ctrl-C is the one that matters here.
pub ] Signal,
CtrlC,
);