Documentation
¶
Overview ¶
batcher is a package that provides a simple batching mechanism the buffer can be configured with a max capacity and a flush interval the buffer will invoke a callback function when the buffer is full or the flush interval is reached
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batcher ¶
type Batcher[T any] struct { // contains filtered or unexported fields }
Batcher is a batcher for any type of data
func (*Batcher[T]) Run ¶
func (b *Batcher[T]) Run()
Run starts the batcher. Only the first call has an effect, and a batcher cannot be restarted once stopped.
func (*Batcher[T]) Stop ¶
func (b *Batcher[T]) Stop()
Stop asks the batcher to flush the remaining items and exit, without waiting for it (use WaitDone). It never blocks and may be called any number of times, from any goroutine, including before Run, in which case the batcher flushes and exits as soon as it runs.
Append must not be called concurrently with or after Stop: once the batcher has exited nothing drains it, so Append may block forever (the buffer is full or the size limit is reached) or leave its items unflushed.
type BatcherOption ¶ added in v0.0.39
BatcherOption is the option for the batcher
func WithFlushCallback ¶ added in v0.0.39
func WithFlushCallback[T any](fn FlushCallback[T]) BatcherOption[T]
WithFlushCallback sets the flush callback of the batcher
func WithFlushInterval ¶ added in v0.0.39
func WithFlushInterval[T any](flushInterval time.Duration) BatcherOption[T]
WithFlushInterval sets the optional flush interval of the batcher
func WithMaxCapacity ¶ added in v0.0.39
func WithMaxCapacity[T any](maxCapacity int) BatcherOption[T]
WithMaxCapacity sets the max capacity of the batcher
func WithMaxSize ¶ added in v0.2.0
func WithMaxSize[T any](maxSize int32) BatcherOption[T]
WithMaxSize sets the max size of the batcher
type FlushCallback ¶
type FlushCallback[T any] func([]T)
FlushCallback is the callback function that will be called when the batcher is full or the flush interval is reached