batcher

package
v0.0.56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 1 Imported by: 0

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 New

func New[T any](opts ...BatcherOption[T]) *Batcher[T]

New creates a new batcher

func (*Batcher[T]) Append

func (b *Batcher[T]) Append(d ...T)

Append appends data to the batcher

func (*Batcher[T]) Run

func (b *Batcher[T]) Run()

Run starts the batcher

func (*Batcher[T]) Stop

func (b *Batcher[T]) Stop()

Stop stops the batcher

func (*Batcher[T]) WaitDone

func (b *Batcher[T]) WaitDone()

WaitDone waits until the batcher is done

type BatcherOption added in v0.0.39

type BatcherOption[T any] func(*Batcher[T])

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL