Skip to content

Commit

Permalink
Don't force flush if write buffer isn't empty
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Apr 5, 2024
1 parent a49c239 commit 211aa30
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ pub(crate) struct ConnectionHandler {
pending_pings: usize,
info_sender: tokio::sync::watch::Sender<ServerInfo>,
ping_interval: Interval,
is_flushing: bool,
flush_observers: Vec<oneshot::Sender<()>>,
}

Expand All @@ -436,7 +435,6 @@ impl ConnectionHandler {
pending_pings: 0,
info_sender,
ping_interval,
is_flushing: false,
flush_observers: Vec::new(),
}
}
Expand Down Expand Up @@ -574,12 +572,12 @@ impl ConnectionHandler {
}
}

if self.handler.is_flushing || self.handler.connection.should_flush() {
if self.handler.connection.should_flush()
|| !self.handler.flush_observers.is_empty()
{
match self.handler.connection.poll_flush(cx) {
Poll::Pending => {}
Poll::Ready(Ok(())) => {
self.handler.is_flushing = false;

for observer in self.handler.flush_observers.drain(..) {
let _ = observer.send(());
}
Expand Down Expand Up @@ -738,7 +736,6 @@ impl ConnectionHandler {
}
}
Command::Flush { observer } => {
self.is_flushing = true;
self.flush_observers.push(observer);
}
Command::Subscribe {
Expand Down

0 comments on commit 211aa30

Please sign in to comment.