ringbuffer

package
v2.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MP1COverwritingRingBuffer

type MP1COverwritingRingBuffer[T any] struct {
	// contains filtered or unexported fields
}

MP1COverwritingRingBuffer is a multi-producer, single-consumer ring buffer with a fixed size that overwrites the oldest item when full.

func NewMP1COverwritingRingBuffer

func NewMP1COverwritingRingBuffer[T any](capacity uint64) *MP1COverwritingRingBuffer[T]

NewMP1COverwritingRingBuffer creates a ring buffer with capacity at least 'capacity', rounding up to the next power of two, so the ring won't grow infinitely.

func (*MP1COverwritingRingBuffer[T]) DumpN

func (rb *MP1COverwritingRingBuffer[T]) DumpN(maxCount uint64) []T

DumpN reads up to 'maxCount' items in a single batch. Returns a slice of length <= maxCount. If empty, returns nil.

This is a single-consumer operation; only one goroutine should call DumpN.

func (*MP1COverwritingRingBuffer[T]) Enqueue

func (rb *MP1COverwritingRingBuffer[T]) Enqueue(val T)

Enqueue writes 'val' into the ring buffer, overwriting the oldest entry if necessary. It never fails or blocks; producers always succeed.

type Writer

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

Writer implements io.Writer and writes complete log lines to a ring buffer. It accumulates partial writes until a newline is seen.

func NewWriter

func NewWriter(rb *MP1COverwritingRingBuffer[string]) *Writer

NewWriter returns a new Writer backed by the given ring buffer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush force writing any buffered data (even if incomplete). This is not part of io.Writer, but can be useful in some logging setups.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer. It scans the input for newline characters, enqueuing each complete log line into the ring buffer. Any bytes after the last newline remain buffered until the next Write.

Jump to

Keyboard shortcuts

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