ringbuffer

package
v0.0.0-...-7ef7dd6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

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 New

func New(cap int) *RingBuffer

New creates new RingBuffer.

func (*RingBuffer) Close

func (rb *RingBuffer) Close() error

Close closes the ringbuffer.

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.

Jump to

Keyboard shortcuts

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