From bae66c49c280209d8b734bcb30938ce73552e8d5 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 23 Nov 2020 16:34:51 +0800 Subject: [PATCH] 1.use local variable i; 2.make sure limiter larger than timer period (#218) Co-authored-by: chris --- example/limit/period/periodlimit.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/limit/period/periodlimit.go b/example/limit/period/periodlimit.go index ec44cd1f..aedcabfa 100644 --- a/example/limit/period/periodlimit.go +++ b/example/limit/period/periodlimit.go @@ -29,7 +29,7 @@ func main() { store := redis.NewRedis(*rdx, *rdxType, *rdxPass) fmt.Println(store.Ping()) - lmt := limit.NewPeriodLimit(seconds, 5, store, *rdxKey) + lmt := limit.NewPeriodLimit(seconds+1, 5, store, *rdxKey) timer := time.NewTimer(time.Second * seconds) quit := make(chan struct{}) defer timer.Stop() @@ -42,6 +42,7 @@ func main() { var wait sync.WaitGroup for i := 0; i < *threads; i++ { wait.Add(1) + i := i go func() { for { select {