Skip to content

Commit 2769999

Browse files
authored
feat(socket): implement send_request API (#204)
2 parents ea0f9e9 + c3b11d3 commit 2769999

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

msg-socket/src/req/socket.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,14 @@ where
139139
self.state.transport_stats.load()
140140
}
141141

142-
pub async fn request(&self, message: Bytes) -> Result<Bytes, ReqError> {
142+
/// Send a request, return the oneshot channel to receive the response.
143+
///
144+
/// It may fail if the underlying socket driver has been closed, or if high water mark is
145+
/// reached.
146+
pub async fn send_request(
147+
&self,
148+
message: Bytes,
149+
) -> Result<oneshot::Receiver<Result<Bytes, ReqError>>, ReqError> {
143150
let (response_tx, response_rx) = oneshot::channel();
144151

145152
let msg = ReqMessage::new(message);
@@ -153,7 +160,13 @@ where
153160
TrySendError::Closed(_) => ReqError::SocketClosed,
154161
})?;
155162

156-
response_rx.await.map_err(|_| ReqError::SocketClosed)?
163+
Ok(response_rx)
164+
}
165+
166+
/// Send a request and await for the response.
167+
pub async fn request(&self, message: Bytes) -> Result<Bytes, ReqError> {
168+
let rx = self.send_request(message).await?;
169+
rx.await.map_err(|_| ReqError::SocketClosed)?
157170
}
158171

159172
/// Tries to connect to the target endpoint with the default options.

0 commit comments

Comments
 (0)