Skip to content

Commit

Permalink
Improve comments on Batcher
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 30, 2023
1 parent f34ace1 commit b946c1e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions syncx/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b946c1e

Please sign in to comment.