Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrSlowReader = errors.New("slow reader detected") ErrBufferClosed = errors.New("buffer was closed") )
ErrSlowReader is returned when a reader has been lapped by the writer.
Functions ¶
This section is empty.
Types ¶
type CircularBuffer ¶
type CircularBuffer[T any] struct { // contains filtered or unexported fields }
CircularBuffer is a generic, lock-based, fixed-size circular buffer. It supports one writer and multiple readers.
func NewCircularBuffer ¶
func NewCircularBuffer[T any](size int) *CircularBuffer[T]
NewCircularBuffer creates a new generic circular buffer.
func (*CircularBuffer[T]) Close ¶
func (b *CircularBuffer[T]) Close()
Close marks the buffer as closed, so readers will no longer block on reading. Readers can still consume remaining items in the buffer, after which they'll receive an ErrBufferClosed error.
func (*CircularBuffer[T]) NewReader ¶
func (b *CircularBuffer[T]) NewReader() *Reader[T]
NewReader creates a new reader associated with the buffer.
func (*CircularBuffer[T]) Write ¶
func (b *CircularBuffer[T]) Write(v T) error
Write adds a new value to the buffer.
type Reader ¶
type Reader[T any] struct { // contains filtered or unexported fields }
Reader represents a single consumer of the CircularBuffer.
Click to show internal directories.
Click to hide internal directories.