Documentation
¶
Overview ¶
Package ringbuffer provides a lock-free ring buffer implementation for storing message history with concurrent read/write support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a lock-free ring buffer for storing message history. It uses atomic operations to allow concurrent reads and writes without mutex contention.
func New ¶
func New(size int) *RingBuffer
New creates a new ring buffer with the specified capacity.
func (*RingBuffer) Cap ¶
func (rb *RingBuffer) Cap() int
Cap returns the capacity of the ring buffer.
func (*RingBuffer) GetAll ¶
func (rb *RingBuffer) GetAll() []any
GetAll returns all messages currently in the buffer in order. This is safe to call concurrently with Push.
func (*RingBuffer) Len ¶
func (rb *RingBuffer) Len() int
Len returns the current number of messages in the buffer.
func (*RingBuffer) Push ¶
func (rb *RingBuffer) Push(msg any)
Push adds a message to the ring buffer. This is safe to call concurrently with other Push and GetAll calls.