RetryPolicy
using Polly.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
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)
{
IRetryPolicyState policyState = policyStateFactory();
Exception ex;
while (true) {
try {
await action().NotOnCapturedContext();
return;
} catch (Exception ex2) {
ex = ex2;
if (!shouldRetryPredicates.Any((ExceptionPredicate predicate) => predicate(ex)))
throw;
if (!policyState.CanRetry(ex))
throw;
}
}
}
}
}