Skip to content

Commit

Permalink
Attempt to reconnect once before giving up on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Apr 29, 2022
1 parent 0abd0cd commit d0da64f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub enum Command {
},
Ping,
Flush {
result: oneshot::Sender<io::Result<()>>,
result: oneshot::Sender<Result<(), io::Error>>,
},
TryFlush,
Connect(ConnectInfo),
Expand Down Expand Up @@ -758,9 +758,21 @@ impl ConnectionHandler {
}
}
Command::Flush { result } => {
result.send(self.connection.flush().await).map_err(|_| {
io::Error::new(io::ErrorKind::Other, "one shot failed to be received")
})?;
if let Err(err) = self.connection.flush().await {
if let Err(err) = self.handle_reconnect().await {
result.send(Err(err)).map_err(|_| {
io::Error::new(io::ErrorKind::Other, "one shot failed to be received")
})?;
} else if let Err(err) = self.connection.flush().await {
result.send(Err(err)).map_err(|_| {
io::Error::new(io::ErrorKind::Other, "one shot failed to be received")
})?;
}
} else {
result.send(Ok(())).map_err(|_| {
io::Error::new(io::ErrorKind::Other, "one shot failed to be received")
})?;
}
}
Command::TryFlush => {
if let Err(err) = self.connection.write_op(ClientOp::TryFlush).await {
Expand Down

0 comments on commit d0da64f

Please sign in to comment.