tokenbucket

package
v0.0.0-...-9648343 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: BSD-3-Clause Imports: 1 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 represents a token bucket.

func New

func New(interval time.Duration, refill, capa int) *Bucket

New initiates a token bucket with a maximum capacity that refills at a certain interval.

func (*Bucket) Cap

func (b *Bucket) Cap() int

func (*Bucket) Delay

func (b *Bucket) Delay() time.Duration

TODO: accurate compute for multiple takes

func (*Bucket) Empty

func (b *Bucket) Empty() bool

Empty checks whether the bucket is currently empty.

func (*Bucket) Set

func (b *Bucket) Set(v int)

Set assigns a specific value to the bucket.

func (*Bucket) SetInterval

func (b *Bucket) SetInterval(i time.Duration)

SetInterval changes the refill interval. Mostly useful for testing.

func (*Bucket) Take

func (b *Bucket) Take(i int) int

Take takes at most i tokens from the bucket.

func (*Bucket) TakeOne

func (b *Bucket) TakeOne() bool

TakeOne takes one token from the bucket.

Jump to

Keyboard shortcuts

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