ringbuffer

package module
v0.0.0-...-02b419d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 0 Imported by: 1

README

Ring Buffer

This is a library for ring buffer operations in Go. A ring buffer, also known as a circular buffer, is a fixed-size data structure that overwrites the oldest data when it becomes full. You can learn more about ring buffers on Wikipedia. The primary goal of this library is to provide a buffer that favors more recent data and prevents back pressure on the buffer.

Channel

This implementation uses Go channels as the underlying buffer. You can define the size and type of the buffer.

Example:

buffer := ringbuffer.NewChannel[int](1)
buffer.Write(1)
buffer.Write(2)

// in a goroutine far away
value := buffer.Read()
// value == 2

Limitations

This library does not currently support:

  • Emitting metrics when data is dropped
  • Timeout/context for a buffer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

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

func NewChannel

func NewChannel[T any](size int) *Channel[T]

func (*Channel[T]) Close

func (b *Channel[T]) Close()

func (*Channel[T]) Read

func (b *Channel[T]) Read() T

func (*Channel[T]) Write

func (b *Channel[T]) Write(value T)

Jump to

Keyboard shortcuts

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