Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
Buffer stores items in a buffer and flushes them when the following conditions are met:
1. The buffer is full 2. The buffer has held items for a certain period of time 3. The buffer has held items with a certain size
func NewBuffer ¶
func NewBuffer[T any, U any](opts BufferOpts[T, U]) *Buffer[T, U]
NewBuffer creates a new buffer for any type T
func (*Buffer[T, U]) BuffItem ¶
func (b *Buffer[T, U]) BuffItem(item T) (chan *FlushResponse[U], error)
BuffItem adds a new item to the buffer. It returns a channel that will receive the result of the flush.
func (*Buffer[T, U]) Start ¶
Start starts the buffer. It returns a function that can be called to stop the buffer.
func (*Buffer[T, U]) StartDebugLoop ¶
func (b *Buffer[T, U]) StartDebugLoop()
type BufferOpts ¶
type BufferOpts[T any, U any] struct { // Name of the buffer. Used for debugging. Name string `validate:"required"` // MaxCapacity is the maximum number of items to hold in buffer before we initiate a flush MaxCapacity int `validate:"required,gt=0"` // FlushPeriod is the maximum time to hold items in buffer before we initiate a flush FlushPeriod time.Duration `validate:"required,gt=0"` // MaxDataSizeInQueue is the maximum number of bytes to hold in buffer before we initiate a flush MaxDataSizeInQueue int `validate:"required,gt=0"` // FlushFunc is the function to call to flush the buffer FlushFunc func(ctx context.Context, items []T) ([]U, error) `validate:"required"` // SizeFunc is the function to call to get the size of an item SizeFunc func(T) int `validate:"required"` // (optional) a zerolog logger L *zerolog.Logger `validate:"omitnil"` // MaxConcurrent is the maximum number of concurrent flushes MaxConcurrent int `validate:"omitempty,gt=0"` // WaitForFlush is the time to wait for the buffer to flush used for backpressure on writers WaitForFlush time.Duration `validate:"omitempty,gt=0"` }
BufferOpts is the configuration for the buffer
type FlushResponse ¶
Click to show internal directories.
Click to hide internal directories.