rate

package
v0.0.0-...-883d5d7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rate provides rate limiting which supports a hierarchy of limiters, each capped by their parent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter interface {
	// New returns a new limiter that is subordinate to this limiter, meaning that its cap rate is also capped by its
	// parent.
	New(capacity int) Limiter

	// Cap returns the capacity per time period.
	Cap(applyParentCaps bool) int

	// SetCap sets the capacity.
	SetCap(capacity int)

	// LastUsed returns the capacity used in the last time period.
	LastUsed() int

	// Use returns a channel that will return nil when the request is successful, or an error if the request cannot be
	// fulfilled.
	Use(amount int) <-chan error

	// Closed returns true if the limiter is closed.
	Closed() bool

	// Close this limiter and any children it may have.
	Close()
}

Limiter provides a rate limiter.

func New

func New(capacity int, period time.Duration) Limiter

New creates a new top-level rate limiter. 'capacity' is the number of units (bytes, for example) allowed to be used in a particular time 'period'.

Jump to

Keyboard shortcuts

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