ratelimiter

package
v0.1.0-beta-3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransRate

func TransRate(rate int64) int64

TransRate trans the rate to multiples of 1000. For NewRateLimiter, the production of rate should be division by 1000.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter is used for limiting the rate of transporting.

func NewRateLimiter

func NewRateLimiter(rate int64, window int64) *RateLimiter

NewRateLimiter creates a RateLimiter instance. rate: how many tokens are generated per second. 0 represents that don't limit the rate. window: generating tokens interval (millisecond, [1,1000]). The production of rate and window should be division by 1000.

func (*RateLimiter) AcquireBlocking

func (rl *RateLimiter) AcquireBlocking(token int64) int64

AcquireBlocking acquires tokens. It will be blocking unit the bucket has enough required number of tokens.

func (*RateLimiter) AcquireNonBlocking

func (rl *RateLimiter) AcquireNonBlocking(token int64) int64

AcquireNonBlocking acquires tokens. It will return -1 immediately when there is no enough number of tokens.

func (*RateLimiter) SetRate

func (rl *RateLimiter) SetRate(rate int64)

SetRate sets rate of RateLimiter.

Jump to

Keyboard shortcuts

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