Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrClosed = fmt.Errorf("closed")
ErrClosed is used to indicate the ringbuffer has been closed.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer implements a fixed-size buffer which will drop oldest data if full.
func (*RingBuffer) Drain ¶
func (rb *RingBuffer) Drain() []interface{}
Drain returns all the data in the buffer.
NOTE: it can be used after closed to make sure the data have been consumed.
func (*RingBuffer) Pop ¶
func (rb *RingBuffer) Pop() (interface{}, error)
Pop pops the value in the buffer.
NOTE: it returns ErrClosed if the buffer has been closed.
func (*RingBuffer) Push ¶
func (rb *RingBuffer) Push(val interface{}) (bool, error)
Push pushes value into buffer and return whether it covers the oldest data or not.
Click to show internal directories.
Click to hide internal directories.