Documentation ¶
Index ¶
Constants ¶
const CapacityUnlimited = 1<<(mathbits.UintSize-1) - 1
CapacityUnlimited specifies the largest possible capacity for a FifoQueue. maximum value for platform-specific int: https://yourbasic.org/golang/max-min-int-uint/
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConstructorOption ¶
ConstructorOptions are optional arguments for the `NewFifoQueue` constructor to specify properties of the FifoQueue.
func WithLengthObserver ¶
func WithLengthObserver(callback QueueLengthObserver) ConstructorOption
WithLengthObserver is a constructor option for NewFifoQueue. Each time the queue's length changes, the queue calls the provided callback with the new length. By default, the QueueLengthObserver is a NoOp. CAUTION:
- QueueLengthObserver implementations must be non-blocking
- The values published to queue length observer might be in different order than the actual length values at the time of insertion. This is a performance optimization, which allows to reduce the duration during which the queue is internally locked when inserting elements.
type FifoQueue ¶
type FifoQueue struct {
// contains filtered or unexported fields
}
FifoQueue implements a FIFO queue with max capacity and length observer. Elements that exceeds the queue's max capacity are silently dropped. By default, the theoretical capacity equals to the largest `int` value (platform dependent). Capacity can be set at construction time via the option `WithCapacity`. Each time the queue's length changes, the QueueLengthObserver is called with the new length. By default, the QueueLengthObserver is a NoOp. A single QueueLengthObserver can be set at construction time via the option `WithLengthObserver`.
Caution: * the QueueLengthObserver must be non-blocking
func NewFifoQueue ¶
func NewFifoQueue(maxCapacity int, options ...ConstructorOption) (*FifoQueue, error)
NewFifoQueue is the Constructor for FifoQueue
type QueueLengthObserver ¶
type QueueLengthObserver func(int)
QueueLengthObserver is a optional callback that can be provided to the `NewFifoQueue` constructor (via `WithLengthObserver` option).