aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Compute.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-03-15 11:18:08 -0500
committerGitHub <noreply@github.com>2026-03-15 11:18:08 -0500
commit032d9a3513642b85379c6b33a479cb7e0a5adc22 (patch)
tree3d87f453f75d858dfa65c24d1e5fc883916736ff /src/slskd/Common/Compute.cs
parent0165b5f6cbae759acfe337170f831a11a45634e9 (diff)
parentd1de2611e3662a318d7f1347996e4cd26ae376a3 (diff)
downloadslskd-032d9a3513642b85379c6b33a479cb7e0a5adc22.tar.gz
Merge pull request #1671 from slskd/retry-do
Add the ability to specify base delay for exponential backoff, add onRetry delegate for Retry.Do
Diffstat (limited to 'src/slskd/Common/Compute.cs')
-rw-r--r--src/slskd/Common/Compute.cs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/slskd/Common/Compute.cs b/src/slskd/Common/Compute.cs
index befceb88..f614d011 100644
--- a/src/slskd/Common/Compute.cs
+++ b/src/slskd/Common/Compute.cs
@@ -26,14 +26,14 @@ namespace slskd
/// </summary>
public static class Compute
{
- public static (int Delay, int Jitter) ExponentialBackoffDelay(int iteration, int maxDelayInMilliseconds = int.MaxValue)
+ public static (int Delay, int Jitter) ExponentialBackoffDelay(int iteration, int baseDelayInMilliseconds = 1000, int maxDelayInMilliseconds = int.MaxValue)
{
iteration = Math.Min(100, iteration);
- var computedDelay = Math.Floor((Math.Pow(2, iteration) - 1) / 2) * 1000;
+ var computedDelay = Math.Floor((Math.Pow(2, iteration) - 1) / 2) * baseDelayInMilliseconds;
var clampedDelay = (int)Math.Min(computedDelay, maxDelayInMilliseconds);
- var jitter = new Random().Next(1000);
+ var jitter = Random.Shared.Next(baseDelayInMilliseconds);
return (clampedDelay, jitter);
}