Skip to content

Commit 597f92b

Browse files
authored
refactor: remove unnecessary receiver field from GracefulShutdown (#131)
1 parent 72884c5 commit 597f92b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/server/graceful.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ use tokio::sync::watch;
1919
/// A graceful shutdown utility
2020
pub struct GracefulShutdown {
2121
tx: watch::Sender<()>,
22-
rx: watch::Receiver<()>,
2322
}
2423

2524
impl GracefulShutdown {
2625
/// Create a new graceful shutdown helper.
2726
pub fn new() -> Self {
28-
let (tx, rx) = watch::channel(());
29-
Self { tx, rx }
27+
let (tx, _) = watch::channel(());
28+
Self { tx }
3029
}
3130

3231
/// Wrap a future for graceful shutdown watching.
3332
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();
3534
GracefulConnectionFuture::new(conn, async move {
3635
let _ = rx.changed().await;
3736
// hold onto the rx until the watched future is completed
@@ -44,9 +43,7 @@ impl GracefulShutdown {
4443
/// This returns a `Future` which will complete once all watched
4544
/// connections have shutdown.
4645
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;
5047

5148
// signal all the watched futures about the change
5249
let _ = tx.send(());

0 commit comments

Comments
 (0)