accumulator

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: BSD-1-Clause 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 {
	// The queue for the items.
	Queue stack.Stack[T]

	// The number of items to accumulate before the queue is flushed.
	FlushSize int

	// The time to wait before flushing the queue.
	FlushInterval time.Duration

	// Reset the flush interval after a push.
	ResetAfterPush bool

	// The function which is called when the queue is flushed.
	FlushFunc func([]T)
	// contains filtered or unexported fields
}

An accumulator adds a number of items to a queue and flushes the queue when the queue is full or a certain time has passed.

The items can then be processed by a worker with the specified handler.

func NewAccumulator

func NewAccumulator[T any](flushSize int, flushInterval time.Duration, flushFunc func([]T)) *Accumulator[T]

NewAccumulator creates a new accumulator which accumulates items and flushes them when the flush size is reached or the flush interval is reached.

func (*Accumulator[T]) Close

func (a *Accumulator[T]) Close()

Close closes the accumulator.

func (*Accumulator[T]) Flush

func (a *Accumulator[T]) Flush()

Flush flushes the queue.

func (*Accumulator[T]) Push

func (a *Accumulator[T]) Push(item T)

Push adds an item to the accumulator.

Jump to

Keyboard shortcuts

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