From b946c1e13c6be16b3fe7194e28df2a861c1897ca Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Wed, 30 Aug 2023 17:49:37 -0500 Subject: [PATCH] Improve comments on Batcher --- syncx/batcher.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/syncx/batcher.go b/syncx/batcher.go index ef276dd..38208e6 100644 --- a/syncx/batcher.go +++ b/syncx/batcher.go @@ -20,14 +20,15 @@ type Batcher[T any] struct { timeout <-chan time.Time } -// NewBatcher creates a new batcher. -func NewBatcher[T any](process func(batch []T), maxItems int, maxAge time.Duration, capacity int, wg *sync.WaitGroup) *Batcher[T] { +// NewBatcher creates a new batcher. Queued items are passed to the `process` callback in batches of `maxItems` maximum +// size. Processing of a batch is triggered by reaching `maxItems` or `maxAge` since the oldest unprocessed item was queued. +func NewBatcher[T any](process func(batch []T), maxItems int, maxAge time.Duration, bufferSize int, wg *sync.WaitGroup) *Batcher[T] { return &Batcher[T]{ process: process, maxItems: maxItems, maxAge: maxAge, wg: wg, - buffer: make(chan T, capacity), + buffer: make(chan T, bufferSize), stop: make(chan bool), batch: make([]T, 0, maxItems), timeout: nil,