batcher

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 5 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 comparable] struct {
	// contains filtered or unexported fields
}

Batcher is a one to many event batcher. It batches events and sends them to the added event channel subscribers. Events are sent to the channels after the interval has elapsed. If events with the same key are received within the interval, the timer is reset.

func New

func New[T comparable](interval time.Duration) *Batcher[T]

New creates a new Batcher with the given interval and key type.

func (*Batcher[T]) Batch

func (b *Batcher[T]) Batch(key T)

Batch adds the given key to the batcher. If an event for this key is already active, the timer is reset. If the batcher is closed, the key is silently dropped.

func (*Batcher[T]) Close

func (b *Batcher[T]) Close()

Close closes the batcher. It blocks until all events have been sent to the subscribers. The batcher will be a no-op after this call.

func (*Batcher[T]) Subscribe

func (b *Batcher[T]) Subscribe(eventCh ...chan<- struct{})

Subscribe adds a new event channel subscriber. If the batcher is closed, the subscriber is silently dropped.

func (*Batcher[T]) WithClock added in v0.12.1

func (b *Batcher[T]) WithClock(clock clock.Clock)

WithClock sets the clock used by the batcher. Used for testing.

Jump to

Keyboard shortcuts

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