We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f3b8d6 commit 4d4ef5fCopy full SHA for 4d4ef5f
pkg/rate/limiter.go
@@ -45,13 +45,11 @@ func (l *Limiter) WaitN(ctx context.Context, n int) error {
45
var (
46
shouldWait bool
47
oldest time.Time
48
- period time.Duration
49
)
50
51
l.mu.Lock()
52
53
{
54
- period = l.period
55
if l.requestsSize()+n > l.limit {
56
shouldWait = true
57
oldest, _ = l.requestAt(l.requestsSize() + n - l.limit - 1)
@@ -66,7 +64,7 @@ func (l *Limiter) WaitN(ctx context.Context, n int) error {
66
64
67
65
// Wait if rate limit is reached.
68
if shouldWait {
69
- waitDuration := period - now.Sub(oldest)
+ waitDuration := l.period - now.Sub(oldest)
70
if waitDuration > 0 {
71
timer := time.NewTimer(waitDuration)
72
defer timer.Stop()
0 commit comments