in pkg/batcher/batcher.go [162:182]
func (b *Batcher[T, U]) waitForIdle() {
timeout := time.NewTimer(b.options.MaxTimeout)
idle := time.NewTimer(b.options.IdleTimeout)
count := 1 // we already got a single trigger
for b.options.MaxItems == 0 || count < b.options.MaxItems {
select {
case <-b.ctx.Done():
return
case <-b.trigger:
count++
if !idle.Stop() {
<-idle.C
}
idle.Reset(b.options.IdleTimeout)
case <-timeout.C:
return
case <-idle.C:
return
}
}
}