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]) Push ¶
func (a *Accumulator[T]) Push(item T)
Push adds an item to the accumulator.
Click to show internal directories.
Click to hide internal directories.