It seems that sometimes Take() is not well controlled when it is run inside a goroutine.
Is this expected behavior?
I have confirmed that by defining take before goroutine, the problem does not occur.
func main() {
rl := ratelimit.New(10)
eg := errgroup.Group{}
for {
eg.Go(func() error {
rl.Take()
time.Sleep(time.Second)
fmt.Println(time.Now().Format("15:04:05.00"))
return nil
})
}
}
// The output shows that the rate limit is not working.
// 16:34:37.16
// 16:34:37.16
// 16:34:37.54
// 16:34:37.54
// 16:34:37.54
// 16:34:37.54
// 16:34:37.54
// 16:34:37.55
// 16:34:37.65
// 16:34:37.75
It seems that sometimes
Take()
is not well controlled when it is run inside a goroutine. Is this expected behavior? I have confirmed that by defining take before goroutine, the problem does not occur.