wip: fix batch

This commit is contained in:
Kevin Franklin Kim 2024-05-30 12:19:55 +02:00
parent 81d4d84868
commit 738ddd94b5
No known key found for this signature in database

View File

@ -38,24 +38,6 @@ func Batch[T any](ctx context.Context, ch <-chan T, batchSize int, fn func([]T))
fn(batch)
batch = make([]T, 0, batchSize) // reset
}
default:
if len(batch) > 0 { // partial
fmt.Println("<< 5")
fn(batch)
batch = make([]T, 0, batchSize) // reset
} else { // empty
// wait for more
select {
case <-ctx.Done():
return
case v, ok := <-ch:
if !ok {
return
}
batch = append(batch, v)
}
}
}
}
}