Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
Click to show internal directories.
Click to hide internal directories.