ratelimit

package
v0.0.0-...-0997622 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2017 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

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

Bucket models a token bucket

func NewBucketWithRate

func NewBucketWithRate(qps float64, capacity int64) *Bucket

NewBucketWithRate creates a new token bucket, with maximum capacity = initial capacity, and a refill rate of qps We use floats for refill calculations, which introduces the possibility of truncation and rounding errors. For "sensible" qps values though, is is acceptable: jbeda did some tests here https://play.golang.org/p/LSKUOGz2LG

func (*Bucket) Available

func (b *Bucket) Available() int64

Available returns the quantity available in the bucket (which may be negative), but does not take it. This function is for diagnostic / informational purposes only - the returned capacity may immediately be inaccurate if another thread is operating on the bucket concurrently.

func (*Bucket) Capacity

func (b *Bucket) Capacity() int64

Capacity returns the maximum capacity of the bucket

func (*Bucket) Take

func (b *Bucket) Take(n int64) time.Duration

Take takes n units from the bucket, reducing the available quantity even below zero, but then returns the amount of time we should wait

func (*Bucket) TakeAvailable

func (b *Bucket) TakeAvailable(max int64) int64

TakeAvailable immediately takes whatever quantity is available, up to max

func (*Bucket) Wait

func (b *Bucket) Wait(n int64)

Wait combines a call to Take with a sleep call

Jump to

Keyboard shortcuts

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