From 217a0d32fc925e3889892ec035d68b313af2d7b0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 21 Feb 2022 17:55:03 -0600 Subject: make TokenBucket easier to resize --- src/slskd/Common/TokenBucket.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/TokenBucket.cs b/src/slskd/Common/TokenBucket.cs index 51a0281b..bce2e913 100644 --- a/src/slskd/Common/TokenBucket.cs +++ b/src/slskd/Common/TokenBucket.cs @@ -100,7 +100,12 @@ namespace slskd CurrentCount = Capacity; Clock = new System.Timers.Timer(interval); - Clock.Elapsed += (sender, e) => Reset(); + Clock.Elapsed += (sender, e) => + { + CurrentCount = Capacity; + Reset(); + }; + Clock.Start(); } @@ -175,6 +180,7 @@ namespace slskd } Capacity = capacity; + CurrentCount = Math.Min(CurrentCount, Capacity); } /// @@ -207,7 +213,6 @@ namespace slskd if (CurrentCount == 0) { await waitForReset.Task.ConfigureAwait(false); - CurrentCount = Capacity; } // take the minimum of requested count or CurrentCount, deduct it from -- cgit v1.2.3