goconcurrentqueue

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueueErrorCodeEmptyQueue            = "empty-queue"
	QueueErrorCodeLockedQueue           = "locked-queue"
	QueueErrorCodeIndexOutOfBounds      = "index-out-of-bounds"
	QueueErrorCodeFullCapacity          = "full-capacity"
	QueueErrorCodeInternalChannelClosed = "internal-channel-closed"
)
View Source
const (
	WaitForNextElementChanCapacity = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FIFO

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

FIFO (First In First Out) concurrent queue

func NewFIFO

func NewFIFO() *FIFO

NewFIFO returns a new FIFO concurrent queue

func (*FIFO) Dequeue

func (st *FIFO) Dequeue() (interface{}, error)

Dequeue dequeues an element. Returns error if queue is locked or empty.

func (*FIFO) DequeueOrWaitForNextElement

func (st *FIFO) DequeueOrWaitForNextElement() (interface{}, error)

DequeueOrWaitForNextElement dequeues an element (if exist) or waits until the next element gets enqueued and returns it. Multiple calls to DequeueOrWaitForNextElement() would enqueue multiple "listeners" for future enqueued elements.

func (*FIFO) DequeueOrWaitForNextElementContext

func (st *FIFO) DequeueOrWaitForNextElementContext(ctx context.Context) (interface{}, error)

DequeueOrWaitForNextElementContext dequeues an element (if exist) or waits until the next element gets enqueued and returns it. Multiple calls to DequeueOrWaitForNextElementContext() would enqueue multiple "listeners" for future enqueued elements. When the passed context expires this function exits and returns the context' error

func (*FIFO) Enqueue

func (st *FIFO) Enqueue(value interface{}) error

Enqueue enqueues an element. Returns error if queue is locked.

func (*FIFO) Get

func (st *FIFO) Get(index int) (interface{}, error)

Get returns an element's value and keeps the element at the queue

func (*FIFO) GetCap

func (st *FIFO) GetCap() int

GetCap returns the queue's capacity

func (*FIFO) GetLen

func (st *FIFO) GetLen() int

GetLen returns the number of enqueued elements

func (*FIFO) IsLocked

func (st *FIFO) IsLocked() bool

IsLocked returns true whether the queue is locked

func (*FIFO) Lock

func (st *FIFO) Lock()

Lock // Locks the queue. No enqueue/dequeue operations will be allowed after this point.

func (*FIFO) Remove

func (st *FIFO) Remove(index int) error

Remove removes an element from the queue

func (*FIFO) RemoveByKey

func (st *FIFO) RemoveByKey(key interface{}) error

func (*FIFO) Unlock

func (st *FIFO) Unlock()

Unlock unlocks the queue

type FixedFIFO

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

Fixed capacity FIFO (First In First Out) concurrent queue

func NewFixedFIFO

func NewFixedFIFO(capacity int) *FixedFIFO

func (*FixedFIFO) Dequeue

func (st *FixedFIFO) Dequeue() (interface{}, error)

Dequeue dequeues an element. Returns error if: queue is locked, queue is empty or internal channel is closed.

func (*FixedFIFO) DequeueOrWaitForNextElement

func (st *FixedFIFO) DequeueOrWaitForNextElement() (interface{}, error)

DequeueOrWaitForNextElement dequeues an element (if exist) or waits until the next element gets enqueued and returns it. Multiple calls to DequeueOrWaitForNextElement() would enqueue multiple "listeners" for future enqueued elements.

func (*FixedFIFO) DequeueOrWaitForNextElementContext

func (st *FixedFIFO) DequeueOrWaitForNextElementContext(ctx context.Context) (interface{}, error)

DequeueOrWaitForNextElementContext dequeues an element (if exist) or waits until the next element gets enqueued and returns it. Multiple calls to DequeueOrWaitForNextElementContext() would enqueue multiple "listeners" for future enqueued elements. When the passed context expires this function exits and returns the context' error

func (*FixedFIFO) Enqueue

func (st *FixedFIFO) Enqueue(value interface{}) error

Enqueue enqueues an element. Returns error if queue is locked or it is at full capacity.

func (*FixedFIFO) GetCap

func (st *FixedFIFO) GetCap() int

GetCap returns the queue's capacity

func (*FixedFIFO) GetLen

func (st *FixedFIFO) GetLen() int

GetLen returns queue's length (total enqueued elements)

func (*FixedFIFO) IsLocked

func (st *FixedFIFO) IsLocked() bool

func (*FixedFIFO) Lock

func (st *FixedFIFO) Lock()

func (*FixedFIFO) Unlock

func (st *FixedFIFO) Unlock()

type Queue

type Queue interface {
	// Enqueue element
	Enqueue(interface{}) error
	// Dequeue element
	Dequeue() (interface{}, error)
	// DequeueOrWaitForNextElement dequeues an element (if exist) or waits until the next element gets enqueued and returns it.
	// Multiple calls to DequeueOrWaitForNextElement() would enqueue multiple "listeners" for future enqueued elements.
	DequeueOrWaitForNextElement() (interface{}, error)
	// DequeueOrWaitForNextElementContext dequeues an element (if exist) or waits until the next element gets enqueued and returns it.
	// Multiple calls to DequeueOrWaitForNextElementContext() would enqueue multiple "listeners" for future enqueued elements.
	// When the passed context expires this function exits and returns the context' error
	DequeueOrWaitForNextElementContext(context.Context) (interface{}, error)
	// Get number of enqueued elements
	GetLen() int
	// Get queue's capacity
	GetCap() int

	// Lock the queue. No enqueue/dequeue/remove/get operations will be allowed after this point.
	Lock()
	// Unlock the queue.
	Unlock()
	// Return true whether the queue is locked
	IsLocked() bool
}

Queue interface with basic && common queue functions

type QueueError

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

func NewQueueError

func NewQueueError(code string, message string) *QueueError

func (*QueueError) Code

func (st *QueueError) Code() string

func (*QueueError) Error

func (st *QueueError) Error() string

Jump to

Keyboard shortcuts

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