gxqueue

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDisposed is returned when an operation is performed on a disposed
	// queue.
	ErrDisposed = errors.New(`queue: disposed`)

	// ErrTimeout is returned when an applicable queue operation times out.
	ErrTimeout = errors.New(`queue: poll timed out`)

	// ErrEmptyQueue is returned when an non-applicable queue operation was called
	// due to the queue's empty item state
	ErrEmptyQueue = errors.New(`queue: empty queue`)
)

Functions

func ExecuteInParallel

func ExecuteInParallel(q *Queue, fn func(interface{}))

ExecuteInParallel will (in parallel) call the provided function with each item in the queue until the queue is exhausted. When the queue is exhausted execution is complete and all goroutines will be killed. This means that the queue will be disposed so cannot be used again.

Types

type CircularUnboundedQueue added in v1.11.14

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

CircularUnboundedQueue is a circular structure and will grow automatically if it exceeds the capacity. CircularUnboundedQueue is not thread-safe.

func NewCircularUnboundedQueue added in v1.11.14

func NewCircularUnboundedQueue(capacity int) *CircularUnboundedQueue

func NewCircularUnboundedQueueWithQuota added in v1.11.16

func NewCircularUnboundedQueueWithQuota(capacity, quota int) *CircularUnboundedQueue

func (*CircularUnboundedQueue) Cap added in v1.11.14

func (q *CircularUnboundedQueue) Cap() int

func (*CircularUnboundedQueue) InitialCap added in v1.11.16

func (q *CircularUnboundedQueue) InitialCap() int

func (*CircularUnboundedQueue) IsEmpty added in v1.11.14

func (q *CircularUnboundedQueue) IsEmpty() bool

func (*CircularUnboundedQueue) Len added in v1.11.14

func (q *CircularUnboundedQueue) Len() int

func (*CircularUnboundedQueue) Peek added in v1.11.14

func (q *CircularUnboundedQueue) Peek() interface{}

func (*CircularUnboundedQueue) Pop added in v1.11.14

func (q *CircularUnboundedQueue) Pop() interface{}

func (*CircularUnboundedQueue) Push added in v1.11.14

func (q *CircularUnboundedQueue) Push(t interface{}) bool

func (*CircularUnboundedQueue) Reset added in v1.11.14

func (q *CircularUnboundedQueue) Reset()

type Queue

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

Queue is the struct responsible for tracking the state of the queue.

func New

func New(hint int64) *Queue

New is a constructor for a new threadsafe queue.

func (*Queue) Dispose

func (q *Queue) Dispose() []interface{}

Dispose will dispose of this queue and returns the items disposed. Any subsequent calls to Get or Put will return an error.

func (*Queue) Disposed

func (q *Queue) Disposed() bool

Disposed returns a bool indicating if this queue has had disposed called on it.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty returns a bool indicating if this bool is empty.

func (*Queue) Get

func (q *Queue) Get(number int64) ([]interface{}, error)

Get retrieves items from the queue. If there are some items in the queue, get will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue.

func (*Queue) GetUntil

func (q *Queue) GetUntil(checker func(item interface{}) bool) ([]interface{}, error)

GetUntil gets a function and returns a list of items that match the checker until the checker returns false. This does not wait if there are no items in the queue.

func (*Queue) Len

func (q *Queue) Len() int64

Len returns the number of items in this queue.

func (*Queue) Peek

func (q *Queue) Peek() (interface{}, error)

Peek returns a the first item in the queue by value without modifying the queue.

func (*Queue) Poll

func (q *Queue) Poll(number int64, timeout time.Duration) ([]interface{}, error)

Poll retrieves items from the queue. If there are some items in the queue, Poll will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue or the provided timeout is reached. A non-positive timeout will block until items are added. If a timeout occurs, ErrTimeout is returned.

func (*Queue) Put

func (q *Queue) Put(items ...interface{}) error

Put will add the specified items to the queue.

type SPMCLockFreeQ added in v1.9.5

type SPMCLockFreeQ interface {
	PushHead(val interface{}) bool
	PopHead() (interface{}, bool)
	PopTail() (interface{}, bool)
}

SPMCLockFreeQ is a lock-free queue.

func NewSPMCLockFreeQ added in v1.9.5

func NewSPMCLockFreeQ(n int) (SPMCLockFreeQ, error)

NewSPMCLockFreeQ new a SPMCLockFreeQ instance.

Jump to

Keyboard shortcuts

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