Package rate provides a rate limiter to rate limit requests that can be
burstable but they should only allowed N per a period defined.
This package differs from the "golang.org/x/time/rate" package as it does not
implement the token bucket algorithm.
NewLimiter returns a new Limiter that allows events up to b tokens during
the given interval.
This Limiter has a different implementation from the 'x/time/rate's Limiter
implementation. 'x/time/rate.Limiter' sends a constant stream of updates
(at a rate of few dozen events per second) over the period of a N minutes
which is the behavior of the token bucket algorithm. It is designed to
flatten bursts in a signal to a fixed output rate.
This rate.Limiter does the opposite of 'x/time/rate.Limiter'. It takes a
somewhat fixed-rate stream of updates and turns it into a stream of
controlled small bursts every N minutes.
WaitN acquires n tokens, blocking until resources are available or ctx is
done. On success, returns nil. On failure, returns ctx.Err() and leaves the
limiter unchanged.
If ctx is already done, WaitN may still succeed without blocking.