Skip to content

Commit 4d4ef5f

Browse files
committed
Update rate limiter
1 parent 7f3b8d6 commit 4d4ef5f

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

pkg/rate/limiter.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ func (l *Limiter) WaitN(ctx context.Context, n int) error {
4545
var (
4646
shouldWait bool
4747
oldest time.Time
48-
period time.Duration
4948
)
5049

5150
l.mu.Lock()
5251

5352
{
54-
period = l.period
5553
if l.requestsSize()+n > l.limit {
5654
shouldWait = true
5755
oldest, _ = l.requestAt(l.requestsSize() + n - l.limit - 1)
@@ -66,7 +64,7 @@ func (l *Limiter) WaitN(ctx context.Context, n int) error {
6664

6765
// Wait if rate limit is reached.
6866
if shouldWait {
69-
waitDuration := period - now.Sub(oldest)
67+
waitDuration := l.period - now.Sub(oldest)
7068
if waitDuration > 0 {
7169
timer := time.NewTimer(waitDuration)
7270
defer timer.Stop()

0 commit comments

Comments
 (0)