@@ -83,7 +83,7 @@ func (lim *Limiter) Burst() int {
83
83
// TokensAt returns the number of tokens available at time t.
84
84
func (lim * Limiter ) TokensAt (t time.Time ) float64 {
85
85
lim .mu .Lock ()
86
- _ , _ , tokens := lim .advance (t ) // does not mutute lim
86
+ _ , tokens := lim .advance (t ) // does not mutate lim
87
87
lim .mu .Unlock ()
88
88
return tokens
89
89
}
@@ -183,7 +183,7 @@ func (r *Reservation) CancelAt(t time.Time) {
183
183
return
184
184
}
185
185
// advance time to now
186
- t , _ , tokens := r .lim .advance (t )
186
+ t , tokens := r .lim .advance (t )
187
187
// calculate new number of tokens
188
188
tokens += restoreTokens
189
189
if burst := float64 (r .lim .burst ); tokens > burst {
@@ -304,7 +304,7 @@ func (lim *Limiter) SetLimitAt(t time.Time, newLimit Limit) {
304
304
lim .mu .Lock ()
305
305
defer lim .mu .Unlock ()
306
306
307
- t , _ , tokens := lim .advance (t )
307
+ t , tokens := lim .advance (t )
308
308
309
309
lim .last = t
310
310
lim .tokens = tokens
@@ -321,7 +321,7 @@ func (lim *Limiter) SetBurstAt(t time.Time, newBurst int) {
321
321
lim .mu .Lock ()
322
322
defer lim .mu .Unlock ()
323
323
324
- t , _ , tokens := lim .advance (t )
324
+ t , tokens := lim .advance (t )
325
325
326
326
lim .last = t
327
327
lim .tokens = tokens
@@ -356,7 +356,7 @@ func (lim *Limiter) reserveN(t time.Time, n int, maxFutureReserve time.Duration)
356
356
}
357
357
}
358
358
359
- t , last , tokens := lim .advance (t )
359
+ t , tokens := lim .advance (t )
360
360
361
361
// Calculate the remaining number of tokens resulting from the request.
362
362
tokens -= float64 (n )
@@ -379,15 +379,11 @@ func (lim *Limiter) reserveN(t time.Time, n int, maxFutureReserve time.Duration)
379
379
if ok {
380
380
r .tokens = n
381
381
r .timeToAct = t .Add (waitDuration )
382
- }
383
382
384
- // Update state
385
- if ok {
383
+ // Update state
386
384
lim .last = t
387
385
lim .tokens = tokens
388
386
lim .lastEvent = r .timeToAct
389
- } else {
390
- lim .last = last
391
387
}
392
388
393
389
return r
@@ -396,7 +392,7 @@ func (lim *Limiter) reserveN(t time.Time, n int, maxFutureReserve time.Duration)
396
392
// advance calculates and returns an updated state for lim resulting from the passage of time.
397
393
// lim is not changed.
398
394
// advance requires that lim.mu is held.
399
- func (lim * Limiter ) advance (t time.Time ) (newT time.Time , newLast time. Time , newTokens float64 ) {
395
+ func (lim * Limiter ) advance (t time.Time ) (newT time.Time , newTokens float64 ) {
400
396
last := lim .last
401
397
if t .Before (last ) {
402
398
last = t
@@ -409,7 +405,7 @@ func (lim *Limiter) advance(t time.Time) (newT time.Time, newLast time.Time, new
409
405
if burst := float64 (lim .burst ); tokens > burst {
410
406
tokens = burst
411
407
}
412
- return t , last , tokens
408
+ return t , tokens
413
409
}
414
410
415
411
// durationFromTokens is a unit conversion function from the number of tokens to the duration
0 commit comments