throttler

package
v0.0.0-...-f5d5260 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Throttler

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

Throttler holds the context for a throttler instance.

func New

func New(refillTokens uint64, refillInterval time.Duration) *Throttler

New instantiates a new Throttler object - refillTokens: number of tokens to issue every refillInterval (below) - refillInterval: interval at which 'refillTokens' should be issued

func (*Throttler) Allow

func (t *Throttler) Allow() bool

Allow checks to see if a particular request should be allowed; ie, it would returns true if we are under the throttling threshold, otherwise false.

func (*Throttler) AllowN

func (t *Throttler) AllowN(n uint64) bool

AllowN checks to see if we will be allowed to do a batch of 'n' tokens; it would return true if we are under the throttling threshold, otherwise false.

Jump to

Keyboard shortcuts

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