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.
Click to show internal directories.
Click to hide internal directories.