queue

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 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 reset 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 provides a Take method for popping elements from the queue head (FIFO). If there are no elements available the Take method blocks until Reset is called.

Reset refills the elements queue.

func NewBlocking

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

NewBlocking returns an initialized Blocking Queue.

func (*Blocking[T]) Peek added in v0.3.0

func (q *Blocking[T]) Peek() T

Peek returns but does not remove the element at the head of the queue.

func (*Blocking[_]) Reset

func (q *Blocking[_]) Reset()

Reset notifies every blocking Take routine that index can be reset. nolint: revive // line too long inspiration from pre go 1.18(generics) code: https://gist.github.com/zviadm/c234426882bfc8acba88f3503edaaa36#file-cond2-go-L54

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