Skip to content

Instantly share code, notes, and snippets.

func batcher[T any](in chan T, out chan []T, batchSize int, timeout time.Duration) {
for {
batch := make([]T, 0, batchSize)
t := time.After(timeout)
for batchReady := false; !batchReady; {
select {
case e := <-in:
batch = append(batch, e)
if len(batch) == batchSize {