Documentation ¶
Index ¶
- type RateLimiter
- func (r *RateLimiter) Limit() int
- func (r *RateLimiter) Remaining() int
- func (r *RateLimiter) ResetAt() time.Time
- func (r *RateLimiter) Reverse()
- func (r *RateLimiter) SetRemaining(remaining int)
- func (r *RateLimiter) Try() (ok bool, wait time.Duration, remain int)
- func (r *RateLimiter) UpdateRemaining() int
- func (r *RateLimiter) Wait()
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
}
A RateLimiter limits the rate at which an action can be performed. It applies neither smoothing (like one could achieve in a token bucket system) nor does it offer any conception of warmup, wherein the rate of actions granted are steadily increased until a steady throughput equilibrium is reached.
func New ¶
func New(limit int, interval time.Duration) *RateLimiter
New creates a new rate limiter for the limit and interval.
func (*RateLimiter) Limit ¶
func (r *RateLimiter) Limit() int
func (*RateLimiter) Remaining ¶
func (r *RateLimiter) Remaining() int
func (*RateLimiter) ResetAt ¶
func (r *RateLimiter) ResetAt() time.Time
func (*RateLimiter) Reverse ¶
func (r *RateLimiter) Reverse()
func (*RateLimiter) SetRemaining ¶
func (r *RateLimiter) SetRemaining(remaining int)
func (*RateLimiter) Try ¶
func (r *RateLimiter) Try() (ok bool, wait time.Duration, remain int)
Try returns true if under the rate limit, or false if over and the remaining time before the rate limit expires.
func (*RateLimiter) UpdateRemaining ¶
func (r *RateLimiter) UpdateRemaining() int
func (*RateLimiter) Wait ¶
func (r *RateLimiter) Wait()
Wait blocks if the rate limit has been reached. Wait offers no guarantees of fairness for multiple actors if the allowed rate has been temporarily exhausted.