Skip to content

Commit

Permalink
Extend RetryHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed Sep 25, 2020
1 parent 7ade7f5 commit 1339f52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

namespace System
{
public class StopRetryingException : Exception
{
public StopRetryingException(string message) : base(message) { }
}

public static partial class RetryHelper
{
private static readonly Func<int, int> s_defaultBackoffFunc = i => Math.Min(i * 100, 60_000);
Expand Down Expand Up @@ -36,6 +41,10 @@ public static void Execute(Action test, int maxAttempts = 5, Func<int, int> back
test();
return;
}
catch (StopRetryingException)
{
throw;
}
catch (Exception e)
{
exceptions.Add(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ await RetryHelper.ExecuteAsync(async () =>

var cts = new CancellationTokenSource();
Task timeoutTask = Task.Delay(30000, cts.Token);
Assert.NotSame(timeoutTask, await Task.WhenAny(disposeTask, connectTask, timeoutTask));
if (await Task.WhenAny(disposeTask, connectTask, timeoutTask) == timeoutTask)
{
throw new StopRetryingException("The connect operation timed out.");
}
cts.Cancel();

await disposeTask;
Expand Down

0 comments on commit 1339f52

Please sign in to comment.