RetryEngine
using System;
using System.Collections.Generic;
using System.Linq;
namespace Polly.Retry
{
internal static class RetryEngine
{
internal static TResult Implementation<TResult>(Func<TResult> action, IEnumerable<ExceptionPredicate> shouldRetryExceptionPredicates, IEnumerable<ResultPredicate<TResult>> shouldRetryResultPredicates, Func<IRetryPolicyState<TResult>> policyStateFactory)
{
IRetryPolicyState<TResult> retryPolicyState = policyStateFactory();
DelegateResult<TResult> delegateOutcome;
Exception ex;
while (true) {
try {
delegateOutcome = (DelegateResult<TResult>)new DelegateResult<TResult>(action());
if (!shouldRetryResultPredicates.Any((ResultPredicate<TResult> predicate) => predicate(((DelegateResult<TResult>)delegateOutcome).Result)))
return ((DelegateResult<TResult>)delegateOutcome).Result;
if (!retryPolicyState.CanRetry((DelegateResult<TResult>)delegateOutcome))
return ((DelegateResult<TResult>)delegateOutcome).Result;
} catch (Exception ex2) {
Exception ex3 = ex = ex2;
if (!shouldRetryExceptionPredicates.Any((ExceptionPredicate predicate) => predicate(ex)))
throw;
if (!retryPolicyState.CanRetry(new DelegateResult<TResult>(ex)))
throw;
}
}
}
}
}