asyncbuf

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchBuffer

type BatchBuffer[T any] struct {
	// contains filtered or unexported fields
}

BatchBuffer collects items and processes them in batches on a background goroutine. It follows the Start -> Enqueue -> Stop lifecycle.

func NewBatchBuffer

func NewBatchBuffer[T any](cfg BatchConfig, fn ProcessBatchFunc[T], logger *zap.SugaredLogger) *BatchBuffer[T]

NewBatchBuffer creates a new batch-oriented async buffer.

func (*BatchBuffer[T]) DroppedCount

func (b *BatchBuffer[T]) DroppedCount() int64

DroppedCount returns the total number of dropped items.

func (*BatchBuffer[T]) Enqueue

func (b *BatchBuffer[T]) Enqueue(item T)

Enqueue submits an item. Non-blocking; drops if the queue is full.

func (*BatchBuffer[T]) Start

func (b *BatchBuffer[T]) Start(wg *sync.WaitGroup)

Start launches the background goroutine. The WaitGroup is incremented so callers can wait for graceful shutdown.

func (*BatchBuffer[T]) Stop

func (b *BatchBuffer[T]) Stop()

Stop signals the background goroutine to drain and exit.

type BatchConfig

type BatchConfig struct {
	QueueSize    int
	BatchSize    int
	BatchTimeout time.Duration
}

BatchConfig holds configuration for a BatchBuffer.

type ProcessBatchFunc

type ProcessBatchFunc[T any] func(batch []T)

ProcessBatchFunc is called with a batch of items to process.

type ProcessFunc

type ProcessFunc[T any] func(item T)

ProcessFunc is called for each individual item.

type TriggerBuffer

type TriggerBuffer[T any] struct {
	// contains filtered or unexported fields
}

TriggerBuffer processes items one at a time on a background goroutine. It follows the Start -> Enqueue -> Stop lifecycle.

func NewTriggerBuffer

func NewTriggerBuffer[T any](cfg TriggerConfig, fn ProcessFunc[T], logger *zap.SugaredLogger) *TriggerBuffer[T]

NewTriggerBuffer creates a new per-item async buffer.

func (*TriggerBuffer[T]) Enqueue

func (b *TriggerBuffer[T]) Enqueue(item T)

Enqueue submits an item. Non-blocking; drops if the queue is full.

func (*TriggerBuffer[T]) Start

func (b *TriggerBuffer[T]) Start(wg *sync.WaitGroup)

Start launches the background goroutine. The WaitGroup is incremented so callers can wait for graceful shutdown.

func (*TriggerBuffer[T]) Stop

func (b *TriggerBuffer[T]) Stop()

Stop signals the background goroutine to drain and exit.

type TriggerConfig

type TriggerConfig struct {
	QueueSize int
}

TriggerConfig holds configuration for a TriggerBuffer.

Jump to

Keyboard shortcuts

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