File tree Expand file tree Collapse file tree 2 files changed +42
-44
lines changed
Expand file tree Collapse file tree 2 files changed +42
-44
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ pub mod jobs;
55pub mod logging;
66pub mod protocol;
77pub mod setup;
8+ pub mod signals;
89pub mod stats;
910pub mod tracker;
1011pub mod udp;
@@ -30,47 +31,3 @@ pub mod ephemeral_instance_keys {
3031 pub static ref RANDOM_SEED : Seed = Rng :: gen ( & mut ThreadRng :: default ( ) ) ;
3132 }
3233}
33-
34- pub mod signals {
35- use log:: info;
36-
37- /// Resolves on `ctrl_c` or the `terminate` signal.
38- pub async fn global_shutdown_signal ( ) {
39- let ctrl_c = async {
40- tokio:: signal:: ctrl_c ( ) . await . expect ( "failed to install Ctrl+C handler" ) ;
41- } ;
42-
43- #[ cfg( unix) ]
44- let terminate = async {
45- tokio:: signal:: unix:: signal ( tokio:: signal:: unix:: SignalKind :: terminate ( ) )
46- . expect ( "failed to install signal handler" )
47- . recv ( )
48- . await ;
49- } ;
50-
51- #[ cfg( not( unix) ) ]
52- let terminate = std:: future:: pending :: < ( ) > ( ) ;
53-
54- tokio:: select! {
55- _ = ctrl_c => { } ,
56- _ = terminate => { }
57- }
58- }
59-
60- /// Resolves when the `stop_receiver` or the `global_shutdown_signal()` resolves.
61- pub async fn shutdown_signal ( stop_receiver : tokio:: sync:: oneshot:: Receiver < u8 > ) {
62- let stop = async { stop_receiver. await . expect ( "Failed to install stop signal." ) } ;
63-
64- tokio:: select! {
65- _ = stop => { } ,
66- _ = global_shutdown_signal( ) => { }
67- }
68- }
69-
70- /// Same as `shutdown_signal()`, but shows a message when it resolves.
71- pub async fn shutdown_signal_with_message ( stop_receiver : tokio:: sync:: oneshot:: Receiver < u8 > , message : String ) {
72- shutdown_signal ( stop_receiver) . await ;
73-
74- info ! ( "{message}" ) ;
75- }
76- }
Original file line number Diff line number Diff line change 1+ use log:: info;
2+
3+ /// Resolves on `ctrl_c` or the `terminate` signal.
4+ pub async fn global_shutdown_signal ( ) {
5+ let ctrl_c = async {
6+ tokio:: signal:: ctrl_c ( ) . await . expect ( "failed to install Ctrl+C handler" ) ;
7+ } ;
8+
9+ #[ cfg( unix) ]
10+ let terminate = async {
11+ tokio:: signal:: unix:: signal ( tokio:: signal:: unix:: SignalKind :: terminate ( ) )
12+ . expect ( "failed to install signal handler" )
13+ . recv ( )
14+ . await ;
15+ } ;
16+
17+ #[ cfg( not( unix) ) ]
18+ let terminate = std:: future:: pending :: < ( ) > ( ) ;
19+
20+ tokio:: select! {
21+ _ = ctrl_c => { } ,
22+ _ = terminate => { }
23+ }
24+ }
25+
26+ /// Resolves when the `stop_receiver` or the `global_shutdown_signal()` resolves.
27+ pub async fn shutdown_signal ( stop_receiver : tokio:: sync:: oneshot:: Receiver < u8 > ) {
28+ let stop = async { stop_receiver. await . expect ( "Failed to install stop signal." ) } ;
29+
30+ tokio:: select! {
31+ _ = stop => { } ,
32+ _ = global_shutdown_signal( ) => { }
33+ }
34+ }
35+
36+ /// Same as `shutdown_signal()`, but shows a message when it resolves.
37+ pub async fn shutdown_signal_with_message ( stop_receiver : tokio:: sync:: oneshot:: Receiver < u8 > , message : String ) {
38+ shutdown_signal ( stop_receiver) . await ;
39+
40+ info ! ( "{message}" ) ;
41+ }
You can’t perform that action at this time.
0 commit comments