diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-21 17:55:03 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-21 17:55:03 -0600 |
| commit | 217a0d32fc925e3889892ec035d68b313af2d7b0 (patch) | |
| tree | 5e6763532dd6a47d3edd8a7c09c41bddc5aa74ca | |
| parent | bc204e74f45e345abf1dd5f5d187900660f5684d (diff) | |
| download | slskd-217a0d32fc925e3889892ec035d68b313af2d7b0.tar.gz | |
make TokenBucket easier to resize
| -rw-r--r-- | src/slskd/Common/TokenBucket.cs | 9 |
1 files changed, 7 insertions, 2 deletions
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); } /// <summary> @@ -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 |
