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: 2 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) Capacity

func (b *Bucket) Capacity() int

Capacity returns the current capacity.

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) TakeOne

func (b *Bucket) TakeOne() bool

TakeOne takes one token from the bucket.

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.

Jump to

Keyboard shortcuts

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