Skip to content

Commit 4209de5

Browse files
committed
Update exit handler of ws
1 parent dc328ad commit 4209de5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

apps/quorum/src/ws.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
crate::server::{State, EXIT},
2+
crate::server::{wait_for_exit, State},
33
anyhow::{anyhow, Result},
44
axum::{
55
extract::{
@@ -16,7 +16,7 @@ use {
1616
sync::atomic::{AtomicUsize, Ordering},
1717
time::Duration,
1818
},
19-
tokio::sync::{broadcast, watch},
19+
tokio::sync::broadcast,
2020
};
2121

2222
pub 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

7473
const 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

Comments
 (0)