queue

package
v0.0.0-...-a5b82e5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package queue provides a simple queue primitive that blocks on Pop() until an entry is available and can block on Push() when a size limit is applied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue is a simple generic queue that uses a backing array.

func New

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

New creates a new Queue that can hold size entries. size of <=0 is infinite.

func (*Queue[A]) Close

func (q *Queue[A]) Close()

Close closes the queue. This should be called by the sender after all Add() calls have finished. Calling Add() after Close() is considered an error.

func (*Queue[A]) Pop

func (q *Queue[A]) Pop() (val A, ok bool)

Pop pops the next value off the Queue. This will block until either Close() is called or a value in the queue can be pulled. If ok is nil, this means that val is the zero value (which was not added to the queue), the Queue had Closed() called and the Queue is empty.

func (*Queue[A]) Push

func (q *Queue[A]) Push(a A)

Push adds an entry to the queue.

Jump to

Keyboard shortcuts

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