RetryPolicy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
namespace Polly.Retry
{
internal static class RetryPolicy
{
public static void Implementation(Action action, IEnumerable<ExceptionPredicate> shouldRetryPredicates, Func<IRetryPolicyState> policyStateFactory)
{
IRetryPolicyState retryPolicyState = policyStateFactory();
Exception ex;
while (true) {
try {
action();
return;
} catch (Exception ex2) {
Exception ex3 = ex = ex2;
if (!shouldRetryPredicates.Any((ExceptionPredicate predicate) => predicate(ex)))
throw;
if (!retryPolicyState.CanRetry(ex))
throw;
}
}
}
public static async Task ImplementationAsync(Func<Task> action, IEnumerable<ExceptionPredicate> shouldRetryPredicates, Func<IRetryPolicyState> policyStateFactory, bool continueOnCapturedContext)
{
IRetryPolicyState policyState = policyStateFactory();
Exception ex;
while (true) {
try {
await action().ConfigureAwait(continueOnCapturedContext);
return;
} catch (Exception ex2) {
ex = ex2;
if (!shouldRetryPredicates.Any((ExceptionPredicate predicate) => predicate(ex))) {
Exception obj = ex2 as Exception;
if (obj == null)
throw ex2;
ExceptionDispatchInfo.Capture(obj).Throw();
}
if (!(await policyState.CanRetryAsync(ex, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext))) {
Exception obj2 = ex2 as Exception;
if (obj2 == null)
throw ex2;
ExceptionDispatchInfo.Capture(obj2).Throw();
}
}
}
}
}
}