Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer[T any] interface { // Enqueue adds an item to the buffer. // It must be safe for concurrent use by multiple goroutines. Enqueue(T) // Dequeue removes and returns an item from the buffer, and true. // If the buffer is empty and closed, Dequeue returns the zero value and false. // If the buffer is empty but not closed, // Dequeue blocks until an item is added to the buffer or the buffer is closed. // It must be safe for concurrent use by multiple goroutines. Dequeue() (T, bool) // Close closes the buffer, // signaling that no more items will be added to it. Close() }
Buffer is a dynamically sized buffer for use in a dynamic channel.
func NewHeap ¶
NewHeap creates a new heap, a.k.a. a priority queue, for use as a buffer in a dynamic channel. It is equivalent to calling NewHeapFunc with cmp.Less.
func NewHeapFunc ¶
NewHeapFunc creates a new heap, a.k.a. a priority queue, for use as a buffer in a dynamic channel. The less function is used to compare elements in the heap, and the top of the heap is always the "least" element.
type Chan ¶
type Chan[T any] struct { Send chan<- T Recv <-chan T // contains filtered or unexported fields }
Chan is a dynamic channel. It is like a Go channel but with a dynamically sized buffer. (Normal Go channels have a fixed-size buffer.) Because of this, sends never block. To send items to the Chan, use its Send field. To receive items from the Chan, use Recv. To signal the end of input, close the Send channel.
func New ¶
New creates a new Chan. This is equivalent to calling NewWithBuffer with a FIFO queue from NewFifo. You must close the Chan's Send channel when you are done sending items. You must also call the Chan's Close method when you are done receiving items.
func NewWithBuffer ¶
NewWithBuffer creates a new Chan with a given buffer. This can be NewFifo for normal channel semantics, NewHeap for priority-queue semantics, or any type implementing the Buffer interface. You must close the Chan's Send channel when you are done sending items. You must also call the Chan's Close method when you are done receiving items.