pchan

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pchan implements an async buffered priority channel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PChan

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

PChan is an async, priority channel of items of type T.

func New

func New[T any]() *PChan[T]

New constructs a new PChan which holds items of type T.

func (*PChan[T]) Apply

func (ch *PChan[T]) Apply(fn func(T))

Apply applies the given function to all items in the channel. The channel is otherwise unmodified.

func (*PChan[T]) Close

func (ch *PChan[T]) Close() []T

Close closes the channel, returning whatever was still queued on the channel.

func (*PChan[T]) Len

func (ch *PChan[T]) Len() int

Len returns the number of items queued.

func (*PChan[T]) Peek

func (ch *PChan[T]) Peek() (T, bool)

Peek returns the highest priority item, if any. The bool is true if an item was available.

func (*PChan[T]) Pop

func (ch *PChan[T]) Pop() (T, bool)

Pop blocks until an item is available, then returns that item. If the channel is already closed, the call returns immediately and the bool value is false.

func (*PChan[T]) Push

func (ch *PChan[T]) Push(val T, withPrio ...int) chan struct{}

Push pushes the given value onto the channel, optionally with the given priority. If no priority is provided, the item receives a priority lower than all other items in the channel. The returned channel is closed when the item has been popped off the channel.

func (*PChan[T]) Range

func (ch *PChan[T]) Range(fn func(T))

Range repeatedly calls the callback with items as they are pushed onto the channel. It stops when the channel is closed.

func (*PChan[T]) String

func (ch *PChan[T]) String() string

String returns a textual representation of the channel.

Jump to

Keyboard shortcuts

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