capacity

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueClosed = errors.New("capacity queue closed")

ErrQueueClosed is returned when the queue is shut down.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter enforces concurrent execution capacity.

Semantics:

capacity > 0  → bounded capacity
capacity == 0 → no capacity (reject all)
capacity < 0  → unlimited capacity

func NewLimiter

func NewLimiter(capacity int) *Limiter

NewLimiter creates a new capacity limiter.

func (*Limiter) Capacity

func (l *Limiter) Capacity() int

Capacity returns the configured capacity limit. Returns negative values to indicate unlimited capacity.

func (*Limiter) InUse

func (l *Limiter) InUse() int

InUse returns the current number of acquired capacity units.

func (*Limiter) Release

func (l *Limiter) Release()

Release releases one unit of capacity.

func (*Limiter) TryAcquire

func (l *Limiter) TryAcquire() bool

TryAcquire attempts to acquire one unit of capacity. Returns true if capacity was acquired, false otherwise.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue provides FIFO (First In, First Out) waiting for capacity. When capacity becomes available, waiters are released in the order they arrived.

func NewQueue

func NewQueue() *Queue

NewQueue creates a new FIFO capacity queue.

func (*Queue) Close

func (q *Queue) Close()

Close shuts down the queue and wakes all waiting goroutines.

func (*Queue) Release

func (q *Queue) Release()

Release wakes exactly one waiter (FIFO order).

func (*Queue) Wait

func (q *Queue) Wait(ctx context.Context) error

Wait blocks the caller until either: - The caller is released (capacity became available), or - ctx is canceled

Returns ErrQueueClosed if the queue is shut down.

Jump to

Keyboard shortcuts

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