batchease

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 4 Imported by: 0

README

batchease

Golang library for processing batches of items, support multi worker, load-balancer, and middleware.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBatchSize      = errors.New("invalid batch size")
	ErrInvalidHandleFn       = errors.New("invalid handle function")
	ErrInvalidNumberOfWorker = errors.New("invalid number of workers")
)

Functions

This section is empty.

Types

type Batcher

type Batcher[T any] struct {
	// contains filtered or unexported fields
}

func New

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

func (*Batcher[T]) AddItem

func (b *Batcher[T]) AddItem(item T)

func (*Batcher[T]) AddWorker

func (b *Batcher[T]) AddWorker(w *Worker[T]) error

func (*Batcher[T]) Run

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

func (*Batcher[T]) SetHandleFn

func (b *Batcher[T]) SetHandleFn(handleFn HandleFunc[T])

func (*Batcher[T]) Shutdown

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

type BatcherOption

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

BatcherOption

func WithDefaultConfig

func WithDefaultConfig[T any]() BatcherOption[T]

func WithSize

func WithSize[T any](size int) BatcherOption[T]

func WithWait

func WithWait[T any](wait time.Duration) BatcherOption[T]

func WithWorkers

func WithWorkers[T any](n int, handleFn HandleFunc[T]) BatcherOption[T]

type HandleFunc

type HandleFunc[T any] func(worker *Worker[T], data []T)

type LoadBalancer

type LoadBalancer[T any] interface {
	Resolve(workers []*Worker[T]) *Worker[T]
}

type RoundRobinLB

type RoundRobinLB[T any] struct {
	// contains filtered or unexported fields
}

func (*RoundRobinLB[T]) Resolve

func (lb *RoundRobinLB[T]) Resolve(workers []*Worker[T]) *Worker[T]

type Worker

type Worker[T any] struct {
	ID string
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker[T any](id string, opts ...WorkerOption[T]) (*Worker[T], error)

type WorkerOption

type WorkerOption[T any] func(w *Worker[T]) error

WorkerOption

func WorkerWithHandleFn

func WorkerWithHandleFn[T any](handleFn HandleFunc[T]) WorkerOption[T]

Jump to

Keyboard shortcuts

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