From a4083b1b1b432102b11f233c8de6a7c4dca13861 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Mon, 23 Oct 2023 14:07:34 +1000 Subject: [PATCH] refactor(batch): Reset timer when there are no items in the batch --- pkg/processor/batch.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/processor/batch.go b/pkg/processor/batch.go index 8baed6e3..5256fa59 100644 --- a/pkg/processor/batch.go +++ b/pkg/processor/batch.go @@ -380,10 +380,12 @@ func (bvp *BatchItemProcessor[T]) batchBuilder(ctx context.Context) { bvp.batches <- batchCopy bvp.batch = bvp.batch[:0] bvp.batchReady <- true + } else { + // Reset the timer if there are no items in the batch. + // If there are items in the batch, one of the workers will reset the timer. + bvp.timer.Reset(bvp.o.BatchTimeout) } - bvp.timer.Reset(bvp.o.BatchTimeout) - bvp.batchMutex.Unlock() } }