queue

package
v0.0.0-...-2393a11 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueClosed = errors.New("the queue is closed for reading and writing")
	ErrQueueEmpty  = errors.New("the queue is empty")
)

Functions

This section is empty.

Types

type MessageQueue

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

MessageQueue represents a threadsafe message queue to be used to retrieve or write messages to.

func NewMessageQueue

func NewMessageQueue() *MessageQueue

NewMessageQueue returns a new MessageQueue.

func (*MessageQueue) Close

func (mq *MessageQueue) Close()

Close closes the queue for future writes or reads. Any attempts to read or write from the queue after close will return ErrQueueClosed. This is safe to call multiple times.

func (*MessageQueue) IsEmpty

func (mq *MessageQueue) IsEmpty() bool

IsEmpty returns if the queue is empty

func (*MessageQueue) Read

func (mq *MessageQueue) Read() (interface{}, error)

Read will read a value from the queue if available, otherwise return an error.

func (*MessageQueue) ReadOrWait

func (mq *MessageQueue) ReadOrWait() (interface{}, error)

ReadOrWait will read a value from the queue if available, else it will wait for a value to become available. This will block forever if nothing gets written or until the queue gets closed.

func (*MessageQueue) Write

func (mq *MessageQueue) Write(msg interface{}) error

Write writes `msg` to the queue.

Jump to

Keyboard shortcuts

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