Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter interface { // Run begins emitting tokens for the ratelimiter. // A call to Run must be followed by a call to Close. Run() // Performed consumes one token from the rate limiter. // If no tokens are available, the call will block until one is. Performed() // Close stops the rate limiter. Any future calls to Performed() will block forever. // Close never returns an error. io.Closer }
A Limiter supports a constant number of Performed() calls every time a certain amount of time passes.
Calls to Performed() when no "action tokens" are available will block until one is available.
func NewRateLimit ¶
Construct a new Limiter with the given count and duration.
Example ¶
rl := NewRateLimit(100, 1*time.Minute) go rl.Run() defer rl.Close() for _, v := range exampleData { rl.Performed() // do something with v _ = v }
Output:
Click to show internal directories.
Click to hide internal directories.