rate

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitManager

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

LimitManager tracks the configured limiters and redistributes capacity when individual limiters go in or out of active use.

func NewLimitManager

func NewLimitManager(rate int64) *LimitManager

NewLimitManager constructs a LimitManager with the specified aggregate rate budget.

func (*LimitManager) NewLimiter

func (m *LimitManager) NewLimiter(key string, r, burst int64) (*Limiter, error)

NewLimiter registers a limiter with the manager and returns it for use. The limiter is configured with the provided sustained rate and burst size.

func (*LimitManager) UpdateInUse

func (m *LimitManager) UpdateInUse(l *Limiter, use bool)

UpdateInUse marks a limiter as being actively used and reapportions the available rate across the currently active limiters.

type Limiter

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

Limiter wraps a token bucket rate limiter and reports usage back to the LimitManager so the shared capacity can be rebalanced.

func (*Limiter) SetInUse

func (l *Limiter) SetInUse(use bool)

SetInUse increments or decrements the active usage counter and notifies the LimitManager when the limiter transitions between idle and active states.

func (*Limiter) WaitN

func (l *Limiter) WaitN(ctx context.Context, n int) error

WaitN acquires n tokens from the underlying rate limiter, blocking as needed.

Jump to

Keyboard shortcuts

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