45
// NewBatcher creates a Batcher. `fn` is the processing function, `opts` are the timing options.
46
// `clock` is usually clock.NewRealTimeSource but can be a fake time source for testing.
47
>
func NewBatcher[T, R any](fn func([]T) R, opts BatcherOptions, timeSource clock.TimeSource) *Batcher[T, R] {
batcher.go
48
>
return &Batcher[T, R]{
49
>
fn: fn,
50
>
opts: opts,
51
>
timeSource: timeSource,
52
>
submitC: make(chan batchPair[T, R]),
53
>
}
54
>
}
55
56
// Add adds an item to the stream and returns when it has been processed, or if the context is