queue

package
v0.30.6 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Data      []byte
	Channel   string
	FrameType protocol.FrameType
}

type Queue

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

Queue is an unbounded queue of Item. The queue is goroutine safe. Inspired by http://blog.dubbelboer.com/2015/04/25/go-faster-queue.html (MIT)

func New

func New(initialCapacity int) *Queue

New Queue returns a new Item queue with initial capacity.

func (*Queue) Add

func (q *Queue) Add(i Item) bool

Add an Item to the back of the queue will return false if the queue is closed. In that case the Item is dropped.

func (*Queue) Cap

func (q *Queue) Cap() int

Cap returns the capacity (without allocations)

func (*Queue) Close

func (q *Queue) Close()

Close the queue and discard all entries in the queue all goroutines in wait() will return

func (*Queue) CloseRemaining

func (q *Queue) CloseRemaining() []Item

CloseRemaining will close the queue and return all entries in the queue. All goroutines in wait() will return.

func (*Queue) Closed

func (q *Queue) Closed() bool

Closed returns true if the queue has been closed The call cannot guarantee that the queue hasn't been closed while the function returns, so only "true" has a definite meaning.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the current length of the queue.

func (*Queue) Remove

func (q *Queue) Remove() (Item, bool)

Remove will remove an Item from the queue. If false is returned, it either means 1) there were no items on the queue or 2) the queue is closed.

func (*Queue) Size

func (q *Queue) Size() int

Size returns the current size of the queue.

func (*Queue) Wait

func (q *Queue) Wait() bool

Wait for a message to be added. If there are items on the queue will return immediately. Will return false if the queue is closed. Otherwise, returns true.

Jump to

Keyboard shortcuts

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