From 4b7d3ddde4ece170faae5643e6388c3aa94e1397 Mon Sep 17 00:00:00 2001 From: Kingsley Chen Date: Tue, 1 Oct 2019 21:55:36 +0800 Subject: [PATCH] Fix the stupid defect --- ratelimit.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ratelimit.go b/ratelimit.go index b286ce5..51a6559 100644 --- a/ratelimit.go +++ b/ratelimit.go @@ -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 }