accumulator

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accumulator

type Accumulator[T any] struct {
	Input chan T
	// contains filtered or unexported fields
}

Accumulator gathers items arriving spaced in time and groups them.

func New

func New[T any](timeout time.Duration, maxSize int, log *zerolog.Logger) *Accumulator[T]

New creates a new accumulator. An Accumulator gathers items arriving spaced in time and groups them.

The main parameters are timeout and maxSize, determining the limits for the accumulator.

An accumulator is started with the start method, which takes fn, a func([]T) argument that will be run every time the limit parameters are reached. After running fn, the accumulator pool is emptied.

Items are put into the accumulator using the <-input channel, making it thread-safe.

func (*Accumulator[T]) Start

func (a *Accumulator[T]) Start(fn func([]T)) error

Start starts the accumulator.

This does not mean the timer will start running. That happens once the first item arrives through the <-input channel. Once the time reaches the timeout or the max size of the accumulator is reached, fn will be run with the slice of items currently in the accumulator.

Jump to

Keyboard shortcuts

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