Skip to content

Instantly share code, notes, and snippets.

@parsibox
Created November 19, 2023 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsibox/5455159a6a6d9581720924d87c589809 to your computer and use it in GitHub Desktop.
Save parsibox/5455159a6a6d9581720924d87c589809 to your computer and use it in GitHub Desktop.
golang rateLimit
rateLimit := time.Second / 100 // 100 messages per second
throttle := time.NewTicker(rateLimit)
for msg := range msgs {
<-throttle.C // Wait for the next tick
go handle(msg) // Process the message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment