@@ -19,19 +19,18 @@ use tokio::sync::watch;
19
19
/// A graceful shutdown utility
20
20
pub struct GracefulShutdown {
21
21
tx : watch:: Sender < ( ) > ,
22
- rx : watch:: Receiver < ( ) > ,
23
22
}
24
23
25
24
impl GracefulShutdown {
26
25
/// Create a new graceful shutdown helper.
27
26
pub fn new ( ) -> Self {
28
- let ( tx, rx ) = watch:: channel ( ( ) ) ;
29
- Self { tx, rx }
27
+ let ( tx, _ ) = watch:: channel ( ( ) ) ;
28
+ Self { tx }
30
29
}
31
30
32
31
/// Wrap a future for graceful shutdown watching.
33
32
pub fn watch < C : GracefulConnection > ( & self , conn : C ) -> impl Future < Output = C :: Output > {
34
- let mut rx = self . rx . clone ( ) ;
33
+ let mut rx = self . tx . subscribe ( ) ;
35
34
GracefulConnectionFuture :: new ( conn, async move {
36
35
let _ = rx. changed ( ) . await ;
37
36
// hold onto the rx until the watched future is completed
@@ -44,9 +43,7 @@ impl GracefulShutdown {
44
43
/// This returns a `Future` which will complete once all watched
45
44
/// connections have shutdown.
46
45
pub async fn shutdown ( self ) {
47
- // drop the rx immediately, or else it will hold us up
48
- let Self { tx, rx } = self ;
49
- drop ( rx) ;
46
+ let Self { tx } = self ;
50
47
51
48
// signal all the watched futures about the change
52
49
let _ = tx. send ( ( ) ) ;
0 commit comments