queue

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 2 Imported by: 10

README

queue GitHub release

GitHub go.mod Go version of a Go module GoDoc reference example

CodeFactor Go Report Card codecov

lint-test grype codeql


Queue is a Go package providing different thread-safe generic queue implementations.

Available queues:

Blocking Queue
  • Waits for the queue have elements available before retrieving from it.
  • TODO:
    • Put() - append an element to the back of the queue
    • Peek() - retrieve but do not remove the head of the queue

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

This section is empty.

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

func NewBlocking[T any](elements []T) *Blocking[T]

NewBlocking returns a new Blocking Queue containing the given elements..

func (*Blocking[T]) Refill added in v0.4.0

func (q *Blocking[T]) Refill(ctx context.Context)

Refill attempts to refill the queue with the elements added at initialization. If there is no room for new elements in the channel the method blocks until there is an available spot for the element or the context is closed.

! There is a chance that this method can block indefinitely if other threads are constantly reading from the queue, so a timeout context would be recommended.

func (*Blocking[T]) Take

func (q *Blocking[T]) Take(
	ctx context.Context,
) (v T)

Take removes and returns the head of the elements queue. If no element is available it waits until the queue

It does not actually remove elements from the elements slice, but it's incrementing the underlying index.

Jump to

Keyboard shortcuts

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