goconcurrentqueue

package
v0.32.10 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

README

This package is copied and modified from https://github.com/enriquebris/goconcurrentqueue

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 specifies waitchan capacity
	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() (event.NormalizedEvent, error)

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

func (*FIFO) DequeueOrWaitForNextElement

func (st *FIFO) DequeueOrWaitForNextElement() (event.NormalizedEvent, 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) Enqueue

func (st *FIFO) Enqueue(value event.NormalizedEvent) 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() (v 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) Unlock

func (st *FIFO) Unlock()

Unlock unlocks the queue

type FixedFIFO

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

FixedFIFO is a fixed capacity FIFO (First In First Out) concurrent queue

func NewFixedFIFO

func NewFixedFIFO(capacity int) *FixedFIFO

NewFixedFIFO creates new obj

func (*FixedFIFO) Dequeue

func (st *FixedFIFO) Dequeue() (event.NormalizedEvent, 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() (event.NormalizedEvent, 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) Enqueue

func (st *FixedFIFO) Enqueue(value event.NormalizedEvent) 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() (v int)

GetLen returns queue's length (total enqueued elements)

func (*FixedFIFO) IsLocked

func (st *FixedFIFO) IsLocked() bool

IsLocked check if the queue is locked

func (*FixedFIFO) Lock

func (st *FixedFIFO) Lock()

Lock the queue

func (*FixedFIFO) Unlock

func (st *FixedFIFO) Unlock()

Unlock queue

type Queue

type Queue interface {
	// Enqueue element
	Enqueue(event.NormalizedEvent) error
	// Dequeue element
	Dequeue() (event.NormalizedEvent, 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() (event.NormalizedEvent, 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

func NewQueue

func NewQueue(cap int) (q Queue)

NewQueue creates a new object depending on capacity

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