Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter is a token bucket rate limiter.
func New ¶
New returns a new RateLimiter. Tokens are refilled at the given interval, up to the given capacity until the context is canceled.
func (*RateLimiter) Acquire ¶
func (rl *RateLimiter) Acquire(ctx context.Context) error
Acquire blocks until a token is available, or the context is canceled.
func (*RateLimiter) Release ¶
func (rl *RateLimiter) Release()
Release returns a token to the bucket.
func (*RateLimiter) TokenCount ¶
func (rl *RateLimiter) TokenCount() int
TokenCount returns the number of tokens in the bucket.
func (*RateLimiter) TryAcquire ¶
func (rl *RateLimiter) TryAcquire() bool
TryAcquire returns true if a token is acquired, false otherwise.
Click to show internal directories.
Click to hide internal directories.