ringbuffer

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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.

Jump to

Keyboard shortcuts

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