batcher

package
v1.0.50 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

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 utility that batches items together and then invokes the provided function on that whenever it reaches the specified size or the timeout is reached.

func New

func New[T any](size int, timeout time.Duration, fn func(batch []*T), background bool) *Batcher[T]

New creates a new Batcher that will invoke the provided function when the batch size is reached. The size is the maximum number of items that can be batched before processing the batch. The timeout is the duration that will be waited before processing the batch.

func (*Batcher[T]) Put

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

Put adds an item to the batch. If the batch is full, or the timeout is reached the batch will be processed.

Jump to

Keyboard shortcuts

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