11use {
2- crate :: server:: { State , EXIT } ,
2+ crate :: server:: { wait_for_exit , State } ,
33 anyhow:: { anyhow, Result } ,
44 axum:: {
55 extract:: {
1616 sync:: atomic:: { AtomicUsize , Ordering } ,
1717 time:: Duration ,
1818 } ,
19- tokio:: sync:: { broadcast, watch } ,
19+ tokio:: sync:: broadcast,
2020} ;
2121
2222pub struct WsState {
@@ -68,7 +68,6 @@ pub struct Subscriber {
6868 sender : SplitSink < WebSocket , Message > ,
6969 ping_interval : tokio:: time:: Interval ,
7070 responded_to_ping : bool ,
71- exit : watch:: Receiver < bool > ,
7271}
7372
7473const PING_INTERVAL_DURATION : Duration = Duration :: from_secs ( 30 ) ;
@@ -88,7 +87,6 @@ impl Subscriber {
8887 sender,
8988 ping_interval : tokio:: time:: interval ( PING_INTERVAL_DURATION ) ,
9089 responded_to_ping : true , // We start with true so we don't close the connection immediately
91- exit : EXIT . subscribe ( ) ,
9290 }
9391 }
9492
@@ -122,7 +120,7 @@ impl Subscriber {
122120 self . sender. send( Message :: Ping ( vec![ ] . into( ) ) ) . await ?;
123121 Ok ( ( ) )
124122 } ,
125- _ = self . exit . changed ( ) => {
123+ _ = wait_for_exit ( ) => {
126124 self . sender. close( ) . await ?;
127125 self . closed = true ;
128126 Err ( anyhow!( "Application is shutting down. Closing connection." ) )
0 commit comments