diff --git a/foundations/src/batcher/mod.rs b/foundations/src/batcher/mod.rs index 5b271a451..dc7c1ef42 100644 --- a/foundations/src/batcher/mod.rs +++ b/foundations/src/batcher/mod.rs @@ -330,6 +330,7 @@ impl BatcherInner { let mut waiters = vec![]; let mut batch = self.active_batch.write().await; let max_documents = self.max_batch_size.load(std::sync::atomic::Ordering::Relaxed); + let mut batches = vec![]; for document in T::Mode::filter_item_iter(documents) { if batch @@ -338,7 +339,7 @@ impl BatcherInner { .unwrap_or(true) { if let Some(b) = batch.take() { - self.queued_batches.send(b).await.ok(); + batches.push(b); } *batch = Some(self.new_batch()); @@ -362,6 +363,10 @@ impl BatcherInner { T::Mode::input_add(&mut b.ops, tracker, document); } + for batch in batches { + self.queued_batches.send(batch).await.ok(); + } + waiters } }