func New()

in batching/batching.go [183:207]


func New(ctx context.Context, in <-chan data.Entry, out chan Batches, timespan time.Duration, options ...Option) (*Batcher, error) {
	if in == nil || out == nil {
		return nil, errors.New("can't call Batcher.New() with a nil in or out channel")
	}

	b := &Batcher{
		timespan:  timespan,
		batchSize: 1000,
		in:        in,
		out:       out,
		log:       slog.Default(),
	}
	b.current = getBatches()
	b.emitter = b.emit

	for _, o := range options {
		if err := o(b); err != nil {
			return nil, err
		}
	}

	go b.run(ctx)

	return b, nil
}