From 597f92b266c822092eeadd76562e70efc2704866 Mon Sep 17 00:00:00 2001 From: ramiroaisen <52116153+ramiroaisen@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:12:39 -0300 Subject: [PATCH] refactor: remove unnecessary receiver field from GracefulShutdown (#131) --- src/server/graceful.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/server/graceful.rs b/src/server/graceful.rs index d649ac1..dcd9f06 100644 --- a/src/server/graceful.rs +++ b/src/server/graceful.rs @@ -19,19 +19,18 @@ use tokio::sync::watch; /// A graceful shutdown utility pub struct GracefulShutdown { tx: watch::Sender<()>, - rx: watch::Receiver<()>, } impl GracefulShutdown { /// Create a new graceful shutdown helper. pub fn new() -> Self { - let (tx, rx) = watch::channel(()); - Self { tx, rx } + let (tx, _) = watch::channel(()); + Self { tx } } /// Wrap a future for graceful shutdown watching. pub fn watch(&self, conn: C) -> impl Future { - let mut rx = self.rx.clone(); + let mut rx = self.tx.subscribe(); GracefulConnectionFuture::new(conn, async move { let _ = rx.changed().await; // hold onto the rx until the watched future is completed @@ -44,9 +43,7 @@ impl GracefulShutdown { /// This returns a `Future` which will complete once all watched /// connections have shutdown. pub async fn shutdown(self) { - // drop the rx immediately, or else it will hold us up - let Self { tx, rx } = self; - drop(rx); + let Self { tx } = self; // signal all the watched futures about the change let _ = tx.send(());