Created
November 19, 2023 17:01
-
-
Save parsibox/5455159a6a6d9581720924d87c589809 to your computer and use it in GitHub Desktop.
golang rateLimit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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