From baad3e48ba1ac211ad5be63014aa364de16dbbc1 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Wed, 7 Feb 2024 17:42:54 +0000 Subject: [PATCH] Expose `queue_len` (#8) --- client/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 6941f1c..30c9d53 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -102,15 +102,16 @@ impl Client { pub fn flush_batch(&self) { let mut guard = self.inner.lock().unwrap(); guard.next_flush_scheduled = None; - let max_batch_size = guard.max_batch_size; - let events = if guard.events.len() < max_batch_size { - mem::take(&mut guard.events) - } else { - guard.events.drain(..max_batch_size).collect() - }; + if !guard.events.is_empty() { + let max_batch_size = guard.max_batch_size; + + let events = if guard.events.len() < max_batch_size { + mem::take(&mut guard.events) + } else { + guard.events.drain(..max_batch_size).collect() + }; - if !events.is_empty() { let clone = self.clone(); guard .runtime @@ -118,6 +119,10 @@ impl Client { } } + pub fn queue_len(&self) -> usize { + self.inner.lock().unwrap().events.len() + } + fn requeue_events(&self, events: Vec) { let mut guard = self.inner.lock().unwrap(); guard.events.extend(events);