Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelQueue ¶
type ChannelQueue[T any] struct { // C is the channel where queue values will be posted. C <-chan T // contains filtered or unexported fields }
ChannelQueue is used to create a Queue that can be consumed as a channel. It creates a worker goroutine to manage sending and receiving.
This is good for cases like:
- When an arbitrary sized queue is needed, but a channel is more convenient.
- Where a dynamically buffered channel is desired to prevent deadlocking on use.
- When it's not known how many consumers/producers will be used ahead of use.
func NewChannelQueue ¶
func NewChannelQueue[T any](ctx context.Context, opts ...ChannelQueueOption) (*ChannelQueue[T], error)
NewChannelQueue creates a new ChannelQueue, and starts a goroutine to keep data flowing.
func (*ChannelQueue[T]) Await ¶
func (q *ChannelQueue[T]) Await()
Await will wait for all ChannelQueue operations to cease before returning.
func (*ChannelQueue[T]) AwaitStop ¶
func (q *ChannelQueue[T]) AwaitStop()
AwaitStop will call ChannelQueue.Stop and wait for all operations to cease before returning.
func (*ChannelQueue[T]) Pop ¶
func (q *ChannelQueue[T]) Pop() (T, bool)
Pop will pop an item from the head of the ChannelQueue. False will be returned if the ChannelQueue is empty.
func (*ChannelQueue[T]) Push ¶
func (q *ChannelQueue[T]) Push(val T) bool
Push will push an item to the tail of the ChannelQueue.
func (*ChannelQueue[T]) PushRanked ¶
func (q *ChannelQueue[T]) PushRanked(val T, priority uint) bool
PushRanked will insert an item in the Queue such that its priority is greater than all elements after it. If priority is set to zero, then the item will be appended to the tail.
func (*ChannelQueue[T]) Stop ¶
func (q *ChannelQueue[T]) Stop()
Stop will signal that the goroutine managing the ChannelQueue should clean up and stop operating. This is implicitly called when the given context is cancelled.
type ChannelQueueOption ¶
type ChannelQueueOption func(conf *channelQueueConfig) error
func OptChannelSize ¶
func OptChannelSize(size int) ChannelQueueOption
OptChannelSize is used to set the buffer size of the input and output channels.
func OptInitialBuffer ¶
func OptInitialBuffer(size int) ChannelQueueOption
OptInitialBuffer is used to set the initial size of the internal Queue.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a concurrency-safe queue implementation.
func (*Queue[T]) Pop ¶
Pop will pop an item from the head of the Queue. False will be returned if the Queue is empty.
func (*Queue[T]) Push ¶
func (q *Queue[T]) Push(val T)
Push will push an item to the tail of the Queue.
func (*Queue[T]) PushRanked ¶
PushRanked will insert an item in the Queue such that its priority is greater than all elements after it. If priority is set to zero, then the item will be appended to the tail.