Skip to content

Commit

Permalink
Add a default value for ExponentialRetryInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
jerviscui committed Mar 15, 2023
1 parent d7d4a4c commit db53ec6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/RetryCore/ExponentialRetryInterval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ExponentialRetryInterval : IRetryIntervalStrategy

private int _count;

private TimeSpan _first;
private TimeSpan _initial;

private TimeSpan _maxDelay;

Expand All @@ -21,13 +21,13 @@ public class ExponentialRetryInterval : IRetryIntervalStrategy
/// <summary>
/// Initializes a new instance of the <see cref="ExponentialRetryInterval"/> class.
/// </summary>
/// <param name="first">The first.</param>
/// <param name="initial">The initial.</param>
/// <param name="max">The maximum.</param>
public ExponentialRetryInterval(TimeSpan first, TimeSpan max)
public ExponentialRetryInterval(TimeSpan initial, TimeSpan? max = null)
{
_first = first;
_pre = first;
_maxDelay = max;
_initial = initial;
_pre = initial;
_maxDelay = max ?? TimeSpan.MaxValue;

_random = new Random();
}
Expand All @@ -43,7 +43,7 @@ public TimeSpan GetInterval()
}

var delta = (Math.Pow(2, _count) - 1.0) * (1.0 + (_random.NextDouble() * (1.1 - 1.0)));
var delay = Math.Min(_first.TotalMilliseconds * delta, _maxDelay.TotalMilliseconds);
var delay = Math.Min(_initial.TotalMilliseconds * delta, _maxDelay.TotalMilliseconds);

_pre = TimeSpan.FromMilliseconds(delay);

Expand Down
2 changes: 1 addition & 1 deletion src/RetryCore/RetryCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>

<Version>0.3.0</Version>
<Version>0.3.1</Version>
<PackageId>$(AssemblyName)</PackageId>
<Description>A library for retrying operations.</Description>
<Authors>jerviscui</Authors>
Expand Down

0 comments on commit db53ec6

Please sign in to comment.