Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brynbellomy/go-ratelimiter

A simple rate limiter.
https://github.com/brynbellomy/go-ratelimiter

Last synced: about 1 month ago
JSON representation

A simple rate limiter.

Awesome Lists containing this project

README

        

# ratelimiter

A simple rate limiter. Warning: it's not perfectly accurate — you will still have to handle overages. With that said, it works pretty well.

```go
import (
"github.com/brynbellomy/go-ratelimiter"
)

func main() {
rl := ratelimiter.New(1000, 1 * time.Second)

for {
doWork(rl)
}
}

func doWork(rl *ratelimiter.RateLimiter) {
rl.GetCapacity(1) // blocks
defer rl.ReleaseCapacity(1)

// ... do some work ...
}
```