ringbuf

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry interface{}

type EntryList

type EntryList []Entry

type NewEntryF

type NewEntryF func() interface{}

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring is a classic generic ring buffer on top of a fixed-sized slice. It is thread-safe.

func New

func New(count int, newf NewEntryF, ringID string) *Ring

New allocates a new Ring instance, with capacity for count entries. If newf is non-nil, it is called count times to pre-allocate the entries. Metrics are exported with a 'ring_id" label.

func (*Ring) Close

func (r *Ring) Close()

Close closes the ring buffer, and causes all blocked readers/writers to be notified.

func (*Ring) Read

func (r *Ring) Read(entries EntryList, block bool) (int, bool)

Read copies entries from the internal ring buffer. If block is true, then Read will block until it is able to read at least one entry (or the Ring is closed). Otherwise it will return immediately if there's no entries available for reading. In case entries is of length zero, the call returns immediately. Returns the number of entries read, or -1 if the RingBuf is closed, and a bool indicating if the read blocked.

func (*Ring) Write

func (r *Ring) Write(entries EntryList, block bool) (int, bool)

Write copies entries to the internal ring buffer. If block is true, then Write will block until it is able to write at least one entry (or the Ring is closed). Otherwise it will return immediately if there's on space left for writing. In case entries is of length zero, the call returns immediately. Returns the number of entries written, or -1 if the RingBuf is closed, and a bool indicating if the write blocked.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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