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 373789f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 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,19 @@ 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));
return Ok(());
}

if let Err(err) = self.connection.flush().await {
result.send(self.connection.flush().await);
return Ok(());
}
} else {
result.send(Ok(()));
}
}
Command::TryFlush => {
if let Err(err) = self.connection.write_op(ClientOp::TryFlush).await {
Expand Down

0 comments on commit 373789f

Please sign in to comment.