ring

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer represents a circular array of data items. It is suitable for (single/multiple) consumers (single/multiple) producers data transfer.

func NewBuffer

func NewBuffer(length int) *Buffer

NewBuffer returns an initialized ring buffer.

func (*Buffer) Close

func (r *Buffer) Close()

Close will close the Buffer.

func (*Buffer) Closed

func (r *Buffer) Closed() bool

Closed checks if buffer is closed.

func (*Buffer) GetAll

func (r *Buffer) GetAll() (ElemArray, bool)

GetAll gets all items in a buffer.

func (*Buffer) Has

func (r *Buffer) Has(e Elem) bool

Has checks if item exists.

func (*Buffer) Put

func (r *Buffer) Put(e Elem) bool

Put an item on the ring buffer.

type Consumer

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

Consumer represents an entity which can read items from a ring buffer. It maintains its own read index, and cache.

func NewConsumer

func NewConsumer(ring *Buffer, callback func(items []Elem, w Writer) bool, w Writer, sortByPriority bool) *Consumer

NewConsumer returns a Consumer, which can read from the passed Buffer.

type Elem added in v0.4.4

type Elem struct {
	Data     []byte
	Metadata *message.Metadata
	Priority byte
}

Elem single data unit of a ring buffer.

type ElemArray added in v0.4.4

type ElemArray []Elem

ElemArray a sortable array of Elem in descending order.

func (ElemArray) Len added in v0.4.4

func (e ElemArray) Len() int

Len complies with the Sort interface.

func (ElemArray) Less added in v0.4.4

func (e ElemArray) Less(i, j int) bool

Less complies with the Sort interface.

func (ElemArray) Swap added in v0.4.4

func (e ElemArray) Swap(i, j int)

Swap complies with the Sort interface.

type Writer added in v0.4.4

type Writer interface {
	Write(data []byte, metadata *message.Metadata, priority byte) (int, error)
	Close() error
}

Writer defines a Writer interface compatible with ring.Elem.

Jump to

Keyboard shortcuts

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