You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How about Limit support custom duration. Sometimes it's hard to limit user's behaviors in per second. but maybe we can limit frequency in 300 times per minute or 150 times per 30 seconds.
The text was updated successfully, but these errors were encountered:
sorry, I made a mistake. I think I understand what mean about Limit;
package main
import (
"fmt"
"time"
"golang.org/x/time/rate"
)
func main() {
// every 1 action per second
{
limiter := rate.NewLimiter(1, 1)
for i := 0; i < 5; i++ {
if limiter.Allow() {
fmt.Printf("act1 ")
}
fmt.Println("wait")
time.Sleep(time.Second)
}
}
// every 3 action per 5 second
limiter := rate.NewLimiter(rate.Every(5*time.Second), 3)
for i := 0; i < 10; i++ {
if limiter.Allow() {
fmt.Printf("act2 ")
}
fmt.Println("wait")
time.Sleep(time.Second)
}
// return a token back to limiter
time.Sleep(5 * time.Second)
for i := 0; i < 10; i++ {
if limiter.Allow() {
fmt.Printf("act2 ")
}
fmt.Println("wait")
time.Sleep(time.Second)
}
}
How about Limit support custom duration. Sometimes it's hard to limit user's behaviors in per second. but maybe we can limit frequency in 300 times per minute or 150 times per 30 seconds.
The text was updated successfully, but these errors were encountered: