Skip to content

Commit

Permalink
If we have nothing to send in the autobatcher, we shouldn't send anyt…
Browse files Browse the repository at this point in the history
…hing.

Fix #12
  • Loading branch information
irevoire committed Oct 25, 2023
1 parent eedc64b commit 4ac8947
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/auto_batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ impl AutoBatcher {
/// batcher.flush(); // .await
/// ```
pub async fn flush(&mut self) -> Result<()> {
if self.batcher.is_empty() {
return Ok(());
}

let message = Message::Batch(Batch {
batch: self.batcher.take(),
context: self.batcher.context.clone(),
Expand Down
4 changes: 4 additions & 0 deletions src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl Batcher {
self.auto_timestamp = false;
}

pub fn is_empty(&self) -> bool {
self.buf.is_empty()
}

/// Push a message into the batcher.
///
/// Returns `Ok(None)` if the message was accepted and is now owned by the
Expand Down

0 comments on commit 4ac8947

Please sign in to comment.