Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MillitokensPerSecond ¶
type MillitokensPerSecond uint64
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
A token bucket rate limiter. Can store at most UINT32_MAX tokens before it saturates. The zero TokenBucket{} is a valid value.
NOT thread-safe
func NewTokenBucket ¶
func NewTokenBucket(rate MillitokensPerSecond, capacity uint32, full bool) *TokenBucket
func (*TokenBucket) AddTokens ¶
func (tb *TokenBucket) AddTokens(n uint32)
Adds n tokens to the bucket.
func (*TokenBucket) Capacity ¶
func (tb *TokenBucket) Capacity() uint32
func (*TokenBucket) Rate ¶
func (tb *TokenBucket) Rate() MillitokensPerSecond
func (*TokenBucket) RemoveTokens ¶
func (tb *TokenBucket) RemoveTokens(n uint32) bool
Removes n tokens from the bucket. If the bucket contained at least n tokens, return true. Otherwise, returns false and sets bucket to contain zero tokens.
func (*TokenBucket) SetCapacity ¶
func (tb *TokenBucket) SetCapacity(capacity uint32)
Sets the bucket's capacity.
func (*TokenBucket) SetRate ¶
func (tb *TokenBucket) SetRate(rate MillitokensPerSecond)
Sets the rate at which the bucket fills with tokens.
Click to show internal directories.
Click to hide internal directories.