Skip to content

Commit

Permalink
Add ConfigureOptions method
Browse files Browse the repository at this point in the history
  • Loading branch information
jerviscui committed Mar 15, 2023
1 parent db53ec6 commit e235cec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/RetryCore/RetryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ public RetryBuilder ConfigureOptions(Action<RetryOptions> configureAction)
return this;
}

/// <summary>
/// Configures the RetryOptions.
/// </summary>
/// <param name="option">The retry option.</param>
/// <returns></returns>
public RetryBuilder ConfigureOptions(RetryOptions option)
{
_configureAction = options =>
{
options.MaxTryCount = option.MaxTryCount;
options.MaxTryTime = option.MaxTryTime;
options.RetryInterval = option.RetryInterval;
};

return this;
}

/// <summary>
/// Retry only on exceptions of the type.
/// </summary>
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.1</Version>
<Version>0.3.2</Version>
<PackageId>$(AssemblyName)</PackageId>
<Description>A library for retrying operations.</Description>
<Authors>jerviscui</Authors>
Expand Down
7 changes: 2 additions & 5 deletions test/RetryCore.Tests/RetryBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ public async Task TryFunction_AsAsync_Test()
[Fact]
public void TryFunction_OverMaxTryTimeException_Test()
{
var r = RetryBuilder.Default.ConfigureOptions(options =>
{
options.MaxTryCount = int.MaxValue;
options.MaxTryTime = TimeSpan.FromSeconds(1);
}).Build(() =>
var options = new RetryOptions { MaxTryCount = int.MaxValue, MaxTryTime = TimeSpan.FromSeconds(1) };
var r = RetryBuilder.Default.ConfigureOptions(options).Build(() =>
{
throw new Exception();
return 1;
Expand Down

0 comments on commit e235cec

Please sign in to comment.