fifoqueue

package
v0.15.3-patch.6-disabl... Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstructorOption

type ConstructorOption func(*FifoQueue) error

ConstructorOptions can are optional arguments for the `NewFifoQueue` constructor to specify properties of the FifoQueue.

func WithCapacity

func WithCapacity(capacity int) ConstructorOption

WithCapacity is a constructor option for NewFifoQueue. It specifies the max number of elements the queue can hold. By default, the theoretical capacity equals to the largest `int` value (platform dependent). The WithCapacity option overrides the previous value (default value or value specified by previous option).

func WithLengthObserver

func WithLengthObserver(callback QueueLengthObserver) ConstructorOption

WithLengthObserver is a constructor option for NewFifoQueue. Each time the queue's length changes, the queue calls the provided callback with the new length. By default, the QueueLengthObserver is a NoOp. Caution: the QueueLengthObserver callback must be non-blocking

type FifoQueue

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

FifoQueue implements a FIFO queue with max capacity and length observer. Elements that exceeds the queue's max capacity are silently dropped. By default, the theoretical capacity equals to the largest `int` value (platform dependent). Capacity can be set at construction time via the option `WithCapacity`. Each time the queue's length changes, the QueueLengthObserver is called with the new length. By default, the QueueLengthObserver is a NoOp. A single QueueLengthObserver can be set at construction time via the option `WithLengthObserver`.

Caution: * The queue is NOT concurrency safe. * the QueueLengthObserver must be non-blocking

func NewFifoQueue

func NewFifoQueue(options ...ConstructorOption) (*FifoQueue, error)

Constructor for FifoQueue

func (*FifoQueue) Front

func (q *FifoQueue) Front() (interface{}, bool)

Front peeks message at the head of the queue (without removing the head).

func (*FifoQueue) Len

func (q *FifoQueue) Len() int

Len returns the current length of the queue.

func (*FifoQueue) Pop

func (q *FifoQueue) Pop() (interface{}, bool)

Pop removes and returns the queue's head element. If the queue is empty, (nil, false) is returned.

func (*FifoQueue) Push

func (q *FifoQueue) Push(element interface{})

Push appends the given value to the tail of the queue. If queue capacity is reached, the message is silently dropped.

type QueueLengthObserver

type QueueLengthObserver func(int)

QueueLengthObserver is a callback that can optionally provided to the `NewFifoQueue` constructor (via `WithLengthObserver` option).

Jump to

Keyboard shortcuts

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