diff --git a/src/lib.rs b/src/lib.rs index a819ea0..46b5f56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -352,6 +352,16 @@ 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 +412,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 +1395,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 }