ratelimit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

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