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 represents a token bucket.
func New ¶
New initiates a token bucket with a maximum capacity that refills at a certain interval.
func (*Bucket) Empty ¶
Empty checks whether the bucket is currently empty.
type LockedBucket ¶
type LockedBucket struct {
// contains filtered or unexported fields
}
LockedBucket represents a token bucket with locking.
func NewLocked ¶
func NewLocked(interval time.Duration, refill, capa int) *LockedBucket
New initiates a token bucket with a maximum capacity that refills at a certain interval.
func (*LockedBucket) Capacity ¶
func (b *LockedBucket) Capacity() int
Capacity returns the current capacity.
func (*LockedBucket) Empty ¶
func (b *LockedBucket) Empty() bool
Empty checks whether the bucket is currently empty.
func (*LockedBucket) Set ¶
func (b *LockedBucket) Set(v int)
Set assigns a specific value to the bucket.
func (*LockedBucket) TakeOne ¶
func (b *LockedBucket) TakeOne() bool
TakeOne takes one token from the bucket.
Click to show internal directories.
Click to hide internal directories.