Skip to content

Instantly share code, notes, and snippets.

@martinos
Created December 5, 2014 16:21
Show Gist options
  • Save martinos/4024fa1e54ebeb737de0 to your computer and use it in GitHub Desktop.
Save martinos/4024fa1e54ebeb737de0 to your computer and use it in GitHub Desktop.
Rate limiter in golang
import "time"
rate_per_sec := 10
throttle := time.Tick(1e9 / rate_per_sec)
for req := range requests {
<-throttle // rate limit our Service.Method RPCs
go client.Call("Service.Method", req, ...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment