store

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package store provides a configurable batching memory queue for streaming data entries with periodic or size-based flushing to a user-provided Flusher.

It is designed for use cases where entries must be collected and written out in batches, such as for logging, metrics, or any buffered data pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Interval  time.Duration
	BatchSize int
	Capacity  int
	// contains filtered or unexported fields
}

type ErrorHandler

type ErrorHandler interface {
	OnError(err error)
}

type Flusher

type Flusher[T any] interface {
	// Flush sends a batch of entries.
	// ctx controls cancellation, batching, or deadlines.
	Flush(ctx context.Context, entries []T) error
}

Flusher is an interface for a batch writer. Implementations are responsible for processing a batch of entries atomically. If an error occurs, Flush should return it.

type Option

type Option func(cfg *Config)

func WithBatchSize

func WithBatchSize(s int) Option

func WithCapacity

func WithCapacity(c int) Option

func WithClock

func WithClock(c quartz.Clock) Option

func WithInterval

func WithInterval(i time.Duration) Option

func WithOnError

func WithOnError(onError ErrorHandler) Option

type Store

type Store[T any] interface {
	// Write queues one or more entries into the buffer.
	Write(entries ...T)
	// Run starts the background processing loop on the provided context.
	// The loop continues until the context is canceled.
	Run(ctx context.Context)
}

Store is an interface for buffered write and lifecycle control. Write buffers entries and Run starts processing of submitted entries in background.

func NewMemory

func NewMemory[T any](flusher Flusher[T], options ...Option) Store[T]

NewMemory creates a new buffered Store using the provided Flusher and configuration options.

Options can control batch size, flush interval, error handling, and clock/ticker source. The returned Store should be started with Run().

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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