rate

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: MPL-2.0 Imports: 3 Imported by: 2

Documentation

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(cap int) Limiter

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

	// SetCap sets the capacity.
	SetCap(cap 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

	// Closes 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