channel

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitMetricLoop

func InitMetricLoop[T any, TagsT metrics.Tags](uq *UnboundedQueue[T], metricsClient metrics.Client, tags TagsT)

Types

type Deque

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

Deque is a typical double-ended queue implemented through a ring buffer.

All operations on Deque locks on its own mutex, so all operations are concurrency-safe.

func NewDeque

func NewDeque[T any](initialCapacity int) *Deque[T]

NewDeque constructs a new deque with the specified initial capacity.

deque capacity is doubled when the length reaches the capacity, i.e. a deque can never be full.

func (*Deque[T]) Cap

func (q *Deque[T]) Cap() int

func (*Deque[T]) Compact

func (q *Deque[T]) Compact(ratio float64)

Compact reallocates the buffer with capacity = Len * ratio.

func (*Deque[T]) GetAndResetLength

func (q *Deque[T]) GetAndResetLength() int

func (*Deque[T]) Len

func (q *Deque[T]) Len() int

func (*Deque[T]) LockedGetAll

func (q *Deque[T]) LockedGetAll() [2][]T

Returns all valid data in two slices.

func (*Deque[T]) LockedPeekFront

func (q *Deque[T]) LockedPeekFront() (T, bool)

func (*Deque[T]) LockedPopFront

func (q *Deque[T]) LockedPopFront() (T, bool)

func (*Deque[T]) LockedPushBack

func (q *Deque[T]) LockedPushBack(obj T)

func (*Deque[T]) PopFront

func (q *Deque[T]) PopFront() (T, bool)

PopFront pops an object from the start of the queue.

This method has O(1) time complexity.

func (*Deque[T]) PushBack

func (q *Deque[T]) PushBack(obj T)

PushBack pushes an object to the end of the queue.

This method has amortized O(1) time complexity and expands the capacity on demand.

type UnboundedQueue

type UnboundedQueue[T any] struct {
	Close context.CancelFunc
	// contains filtered or unexported fields
}

UnboundedQueue is an unbounded channel.

func NewUnboundedQueue

func NewUnboundedQueue[T any](initialCapacity int) *UnboundedQueue[T]

Creates a new UnboundedQueue with the specified initial capacity.

func (*UnboundedQueue[T]) Length

func (uq *UnboundedQueue[T]) Length() int

func (*UnboundedQueue[T]) Receiver

func (uq *UnboundedQueue[T]) Receiver() <-chan T

Receiver returns the channel that can be used for receiving from this UnboundedQueue.

func (*UnboundedQueue[T]) Send

func (uq *UnboundedQueue[T]) Send(obj T)

Sends an item to the queue.

Since the channel capacity is unbounded, send operations always succeed and never block.

Jump to

Keyboard shortcuts

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