ratelimit

package
v2.0.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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