Skip to content

Commit

Permalink
async:when the client request failed. Learn from ttrpc-go
Browse files Browse the repository at this point in the history
The error type shuld more friendly to external interfaces

Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire committed Oct 12, 2024
1 parent 0210c7a commit 72df5e9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/asynchronous/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ impl Client {
self.req_tx
.send(SendingMessage::new(msg))
.await
.map_err(|e| Error::Others(format!("Send packet to sender error {e:?}")))?;
.map_err(|e| Error::LocalClosed)?;

let result = if timeout_nano == 0 {
rx.recv()
.await
.ok_or_else(|| Error::Others("Receive packet from receiver error".to_string()))?
.ok_or_else(|| Error::RemoteClosed)?
} else {
tokio::time::timeout(
std::time::Duration::from_nanos(timeout_nano as u64),
rx.recv(),
)
.await
.map_err(|e| Error::Others(format!("Receive packet timeout {e:?}")))?
.ok_or_else(|| Error::Others("Receive packet from receiver error".to_string()))?
.ok_or_else(|| Error::RemoteClosed)?
};

let msg = result?;
Expand Down

0 comments on commit 72df5e9

Please sign in to comment.