Skip to content

Commit

Permalink
Fix the stupid defect
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsamchen committed Oct 1, 2019
1 parent f633805 commit 4b7d3dd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,12 @@ func (tb *Bucket) currentTick(now time.Time) int64 {
// available in the bucket at the given time, which must
// be in the future (positive) with respect to tb.latestTick.
func (tb *Bucket) adjustavailableTokens(tick int64) {
lastTick := tb.latestTick
tb.latestTick = tick
if tb.availableTokens >= tb.capacity {
return
}
tb.availableTokens += (tick - tb.latestTick) * tb.quantum
tb.availableTokens += (tick - lastTick) * tb.quantum
if tb.availableTokens > tb.capacity {
tb.availableTokens = tb.capacity
}
Expand Down

0 comments on commit 4b7d3dd

Please sign in to comment.