Documentation ¶
Overview ¶
Package pchan implements an async buffered priority channel.
Index ¶
- type PChan
- func (ch *PChan[T]) Apply(fn func(T))
- func (ch *PChan[T]) Close() []T
- func (ch *PChan[T]) Len() int
- func (ch *PChan[T]) Peek() (t T, ok bool)
- func (ch *PChan[T]) Pop() (t T, ok bool)
- func (ch *PChan[T]) Push(val T, withPrio ...int) chan struct{}
- func (ch *PChan[T]) Range(fn func(T))
- func (ch *PChan[T]) String() string
- func (ch *PChan[T]) Wait()
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 (*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]) Peek ¶
Peek returns the highest priority item, if any. The bool is true if an item was available.
func (*PChan[T]) Pop ¶
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 ¶
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.