queue

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package queue provides a queue to processes elements in FIFO order using a specified handler, while allowing non-blocking writes to the queue. The queue may be bounded in size or unbounded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

A Queue is a set of elements that are processed in FIFO order. The writes to the queue are non-blocking and the client can read from a channel it can access by Receive(). The size of the queue is either bounded or unbounded. Note that counters such as max/count used for synchronization are managed under the queue lock, while counters for book keeping are handled via the atomic package.

func NewBounded

func NewBounded(name string, max int) (*Queue, error)

NewBounded creates a new bounded queue.

func NewUnbounded

func NewUnbounded(name string) (*Queue, error)

NewUnbounded creates a new unbounded queue.

func (*Queue) Close

func (q *Queue) Close()

Close closes the queue.

func (*Queue) DequeueCount

func (q *Queue) DequeueCount() int64

DequeueCount returns the number of elements dequeued from the queue.

func (*Queue) EnqueueCount

func (q *Queue) EnqueueCount() int64

EnqueueCount returns the number of elements enqueued in the queue.

func (*Queue) Receive

func (q *Queue) Receive() chan interface{}

Receive returns the channel that the queue will output its elements to the client.

func (*Queue) Run

func (q *Queue) Run()

Run starts processing the Queue.

func (*Queue) String

func (q *Queue) String() string

String returns a string representation of the queue and its state.

func (*Queue) Write

func (q *Queue) Write(v interface{}) error

Write writes an element to the queue if the queue is not closed and if it has space.

Jump to

Keyboard shortcuts

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