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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! The async counterparts of [`cosca::stop`](crate::stop): what [`tokio::Child::terminate`], its
//! `graceful_shutdown` and the two tree calls run before they wait, as an action the caller chooses
//! ([`tokio::Command::graceful_stop`](crate::tokio::Command::graceful_stop)) and the functions it is
//! composed of.
//!
//! An action is an async function of a [`StopTarget`], the same type the sync actions take. Each prepared
//! function here is the sync one of the same name over the same target, with its waits awaited: no
//! runtime thread blocks and no wait for a process uses the blocking pool. That holds for these
//! functions, not for an action that also calls the blocking ones of [`cosca::stop`](crate::stop) over
//! the same target. A prepared function that sends and does not wait (`send_signal`,
//! `send_ctrl_break_to_group`) is the sync function made `async`, so an action composes it as it
//! composes the others.
//!
//! [`tokio::Child::terminate`]: crate::tokio::Child::terminate
use Future;
use Pin;
use Duration;
use crateError;
use crate;
/// What an async stop action returns: a boxed future of the action's answer that borrows its
/// [`StopTarget`] and is `Send`, so the call that runs it can be spawned. Box an `async` block that
/// awaits the prepared functions of this module:
///
/// ```no_run
/// # #[cfg(unix)] fn demo() {
/// use cosca::tokio::{stop, Command};
/// use cosca::Signal;
///
/// let mut command = Command::new();
/// command.arg("my-service");
/// command.graceful_stop(|target| Box::pin(async move { stop::send_signal(target, Signal::Int).await }));
/// # }
/// ```
pub type StopFuture<'a> = ;
/// The async driver of the waits a stop makes (the proxy's spawn uses the blocking pool, as every async
/// spawn does).
pub &'a crateChild);
/// The stop a child does when its command set none. As [`stop::default`](crate::stop::default), with the
/// proxy's wait awaited on Windows; an async action calls this one, not the sync one.
///
/// # Panics
///
/// On Windows: see [`stop::default`](crate::stop::default#panics).
pub async
/// Unix: sends `signal`, and does not wait. As [`stop::send_signal`](crate::stop::send_signal), with the
/// same rules, on a root target and on a tree target.
pub async
/// Windows: sends `CTRL_BREAK` to the child's console process group from this process, and does not wait.
/// As [`stop::send_ctrl_break_to_group`](crate::stop::send_ctrl_break_to_group).
pub async
/// Windows: sends `event` to the console of the child, from a process of its own. As
/// [`stop::send_console_event_via_proxy`](crate::stop::send_console_event_via_proxy), with the wait for the
/// proxy awaited: no runtime thread blocks, and the wait has no cap.
///
/// The proxy is started with [`tokio::Command`](crate::tokio::Command), on the blocking pool as every async
/// spawn is, and the wait for its exit is registered with the OS.
///
/// After a dropped call, whether the event was sent is unknown. A proxy that had started is ended: by the
/// drop, which kills and reaps it before returning, when the call already held it; by the start, when it
/// completes on the pool, if the drop came during the start (the proxy has run since it was created, so it
/// may have attached and sent before it was ended).
///
/// # Panics
///
/// On Windows: see
/// [`stop::send_console_event_via_proxy`](crate::stop::send_console_event_via_proxy#panics).
pub async
/// Waits up to `grace` for the child's root to exit, and whether it did, through the child's handle. As
/// [`StopTarget::wait_exit`], awaited: the wait reaps nothing, and the same for a root and a tree target.
///
/// # Runtime
///
/// On Unix, a non-zero `grace` arms a timer and registers the child with the reactor: it needs a runtime
/// with the IO **and** time drivers enabled (the `#[tokio::main]` / `#[tokio::test]` defaults), and on a
/// hand-built runtime missing either, tokio panics rather than returning a typed error. On Windows the
/// wait holds no thread and needs neither driver.
pub async