Documentation
¶
Overview ¶
Package queue provides different thread-safe generic queue implementations.
The blocking waits for the queue have elements available before retrieving from it. The blocking queue can be refilled in order to make all elements available again.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoElementsAvailable = errors.New("no elements available in the queue")
ErrNoElementsAvailable is an error returned whenever there are no elements available to be extracted from a queue.
Functions ¶
This section is empty.
Types ¶
type Blocking ¶
type Blocking[T any] struct { // contains filtered or unexported fields }
Blocking provides a read-only queue for a list of T.
It supports operations for retrieving and adding elements to a FIFO queue. If there are no elements available the retrieve operations wait until elements are added to the queue.
func NewBlocking ¶
NewBlocking returns a new Blocking Queue containing the given elements.
func (*Blocking[T]) Get ¶ added in v0.6.0
Get removes and returns the head of the elements queue. If no element is available it returns an ErrNoElementsAvailable error.
It does not actually remove elements from the elements slice, but it's incrementing the underlying index.
func (*Blocking[T]) Peek ¶ added in v0.3.0
func (q *Blocking[T]) Peek() T
Peek retrieves but does not return the head of the queue.
func (*Blocking[T]) Put ¶ added in v0.6.0
func (q *Blocking[T]) Put(elem T)
Put inserts the element to the tail the queue, while also increasing the queue size.
func (*Blocking[T]) Reset ¶
func (q *Blocking[T]) Reset()
Reset sets the queue elements index to 0. The queue will be in its initial state.
func (*Blocking[T]) Take ¶
func (q *Blocking[T]) Take() (v T)
Take removes and returns the head of the elements queue. If no element is available it waits until the queue has an element available.
It does not actually remove elements from the elements slice, but it's incrementing the underlying index.
type Option ¶ added in v0.6.0
type Option interface {
// contains filtered or unexported methods
}
An Option configures a Queue using the functional options paradigm.
func WithCapacity ¶ added in v0.6.0
WithCapacity specifies a fixed capacity for a queue.
type Queue ¶ added in v0.6.0
type Queue[T any] interface { // Peek retrieves but does not remove the head of the queue. Peek() T // Get retrieves and removes the head of the queue. Get() (T, error) // Put inserts the element to the tail of the queue. Put(T) }
Queue is a collection that orders elements in a FIFO order. This interface provides basic methods for adding and extracting elements from the queue. Items are extracted from the head of the queue and added to the tail of the queue.