buffered

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package buffered provides a buffered writer base for batch writes.

Index

Constants

View Source
const DefaultBatchSize = 10

DefaultBatchSize is the default number of transactions to buffer before flushing.

View Source
const DefaultFlushInterval = 30 * time.Second

DefaultFlushInterval is the default interval between automatic flushes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BatchSize is the number of transactions to buffer before flushing.
	// Defaults to DefaultBatchSize.
	BatchSize int
	// FlushInterval is the interval between automatic flushes.
	// Defaults to DefaultFlushInterval.
	FlushInterval time.Duration
}

Config holds configuration for buffered writing.

type Flusher

type Flusher func(transactions []*api.TransactionDetails) error

Flusher is called when the buffer needs to be flushed.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer buffers transactions and flushes them in batches.

func New

func New(flusher Flusher, cfg Config, logger *slog.Logger) *Writer

New creates a new buffered writer with the given flusher function.

func (*Writer) BufferLen

func (w *Writer) BufferLen() int

BufferLen returns the current number of buffered transactions.

func (*Writer) Write

func (w *Writer) Write(ctx context.Context, in <-chan *api.TransactionDetails, ackChan chan<- string) error

Write consumes transactions from the input channel and buffers them for batch writes.

Jump to

Keyboard shortcuts

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