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 ¶
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.