From 8e588c9088a6362d4fa0fce680bc23cc8bd68b9b Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Fri, 18 Apr 2025 17:26:59 +0300 Subject: [PATCH 1/2] Add a way to figure out that the remote has closed without having to try to send something Both quinn and tokio::mpsc support this! --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a819ea0..da4fb24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -352,6 +352,15 @@ pub mod channel { } } + pub async fn closed(&mut self) + where T: RpcMessage, + { + match self { + Sender::Tokio(tx) => tx.closed().await, + Sender::Boxed(sink) => sink.closed().await, + } + } + #[cfg(feature = "stream")] pub fn into_sink(self) -> impl n0_future::Sink + Send + 'static where @@ -402,6 +411,9 @@ pub mod channel { value: T, ) -> Pin> + Send + '_>>; + /// Await the sender close + fn closed(&mut self) -> Pin + Send + '_>>; + /// True if this is a remote sender fn is_rpc(&self) -> bool; } @@ -1382,6 +1394,12 @@ pub mod rpc { }) } + fn closed(&mut self) -> Pin + Send + '_>> { + Box::pin(async move { + self.send.stopped().await.ok(); + }) + } + fn is_rpc(&self) -> bool { true } From 45d5fd6556670d91f0781e7c36cc5a0ac1e81039 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Fri, 18 Apr 2025 17:30:42 +0300 Subject: [PATCH 2/2] fmt & clippy --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index da4fb24..46b5f56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -353,7 +353,8 @@ pub mod channel { } pub async fn closed(&mut self) - where T: RpcMessage, + where + T: RpcMessage, { match self { Sender::Tokio(tx) => tx.closed().await,