From c3b11d39bd88456fc9ba6eea10abc1fcad2be61e Mon Sep 17 00:00:00 2001 From: thedevbirb Date: Thu, 26 Feb 2026 15:04:14 +0100 Subject: [PATCH] feat(socket): implement send_request API --- msg-socket/src/req/socket.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/msg-socket/src/req/socket.rs b/msg-socket/src/req/socket.rs index 272ae5fd..5ec9c494 100644 --- a/msg-socket/src/req/socket.rs +++ b/msg-socket/src/req/socket.rs @@ -139,7 +139,14 @@ where self.state.transport_stats.load() } - pub async fn request(&self, message: Bytes) -> Result { + /// Send a request, return the oneshot channel to receive the response. + /// + /// It may fail if the underlying socket driver has been closed, or if high water mark is + /// reached. + pub async fn send_request( + &self, + message: Bytes, + ) -> Result>, ReqError> { let (response_tx, response_rx) = oneshot::channel(); let msg = ReqMessage::new(message); @@ -153,7 +160,13 @@ where TrySendError::Closed(_) => ReqError::SocketClosed, })?; - response_rx.await.map_err(|_| ReqError::SocketClosed)? + Ok(response_rx) + } + + /// Send a request and await for the response. + pub async fn request(&self, message: Bytes) -> Result { + let rx = self.send_request(message).await?; + rx.await.map_err(|_| ReqError::SocketClosed)? } /// Tries to connect to the target endpoint with the default options.