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.
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
This library does not currently support:
- Emitting metrics when data is dropped
- Timeout/context for a buffer