Skip to content

Commit

Permalink
Never flush without items
Browse files Browse the repository at this point in the history
  • Loading branch information
gzuidhof committed Nov 21, 2024
1 parent 7567839 commit 28f727d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (b *Batcher[T]) start(ctx context.Context,

// If the batcher is cancelled and the buffer is not empty, we want to flush the
// remaining items with the maximum batch size, so we skip until we reach max size or the buffer is empty.
skipFlush := isCancelled && len(b.buffer) > 0 && !isMaxSize
skipFlush := (isCancelled && len(b.buffer) > 0 && !isMaxSize) || len(items) == 0

if !skipFlush {
// We need to copy the slice to make sure that the slice that is passed is valid even if asynchronously
Expand Down

0 comments on commit 28f727d

Please sign in to comment.