Documentation ¶
Overview ¶
Package rlimit contains utilities to help with complex rate limiting scenarios. The RateLimiter struct works by using a combination of a ticker that ticks at a fixed rate, and a specified limit on the number of ticks allowed before waiting for a reset. This was developed because an API that my application was consuming allowed querying at a rate of 50 calls/min, up to a maximum of 1000 calls per hour, and I needed a way to create long-running processes that could get the data as soon as possible without exceeding the API's limits.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimiter ¶
type RateLimiter struct { // Channel to carry tick events Tick chan time.Time // contains filtered or unexported fields }
func NewRateLimiter ¶
func NewRateLimiter(tickInterval time.Duration, limit uint, resetInterval time.Duration) *RateLimiter
Creates a new rate limiter.
func (*RateLimiter) Count ¶
func (r *RateLimiter) Count()
Decrements the limit left - not to be used when waiting for a tick using Wait()
func (*RateLimiter) LimitLeft ¶
func (r *RateLimiter) LimitLeft() uint
Returns the number of ticks left until the limiter blocks and waits for the reset timer.
func (*RateLimiter) Stop ¶
func (r *RateLimiter) Stop()
Stops the internal ticker and closes the Tick channel