Documentation ¶
Overview ¶
Package ratelimit implements rate limiting of functions using a leaky bucket algorithm
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
}
func PerSecond ¶
func PerSecond(rate float64, capacity int) *RateLimiter
PerSecond creates a ratelimiter that executes a maximum number of operations per second
func (*RateLimiter) Do ¶
func (rl *RateLimiter) Do(ctx context.Context, fn Func) bool
Do attempts to queue work for the rate limiter, returns false if it could not be queued. Each function queued will be executed in a separate goroutine so if the functions are long running, this could result in a large number of active goroutines, depending on the rate of the limiter
func (*RateLimiter) Drain ¶
func (rl *RateLimiter) Drain()
Drain runs remaining work to completion and then stops the rate limiter
func (*RateLimiter) Stop ¶
func (rl *RateLimiter) Stop()
Stop turns off the rate limiter immediately, losing any queued work
Click to show internal directories.
Click to hide internal directories.