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 ¶
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 ¶
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) Take ¶
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 ¶
TakeAvailable immediately takes whatever quantity is available, up to max