queue

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Holder

type Holder[T any] struct {
	// contains filtered or unexported fields
}

Holder provides synchronized access to a *Queue[T].

func NewHolder

func NewHolder[T any](q *Queue[T]) *Holder[T]

NewHolder creates a new Holder[T] that contains the provided *Queue[T].

func (*Holder[T]) Acquire

func (h *Holder[T]) Acquire() *Queue[T]

Acquire attempts to acquire the *Queue[T]. If the *Queue[T] has already been acquired the call blocks. When the *Queue[T] is no longer required, you MUST call Release() to relinquish acquisition.

func (*Holder[T]) Len

func (h *Holder[T]) Len() int

Len returns the length of the *Queue[T].

func (*Holder[T]) Release

func (h *Holder[T]) Release(q *Queue[T])

Release returns the *Queue[T] back to the Holder[T]. Once the *Queue[T] has been released, it is no longer safe to call its methods.

func (*Holder[T]) Wait

func (h *Holder[T]) Wait() <-chan *Queue[T]

Wait returns a channel that's signaled when the *Queue[T] contains at least one item. When the *Queue[T] is no longer required, you MUST call Release() to relinquish acquisition.

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue[T] is a segmented FIFO queue of Ts.

func New

func New[T any](size int) *Queue[T]

New creates a new instance of Queue[T].

  • size is the size of each Queue segment

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() *T

Dequeue removes and returns the item from the front of the queue.

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(item T)

Enqueue adds the specified item to the end of the queue. If the current segment is full, a new segment is created.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len returns the total count of enqueued items.

Jump to

Keyboard shortcuts

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