RetryPolicyState
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Polly.Retry
{
internal class RetryPolicyState : IRetryPolicyState
{
private readonly Func<Exception, Context, Task> _onRetryAsync;
private readonly Action<Exception, Context> _onRetry;
private readonly Context _context;
public RetryPolicyState(Func<Exception, Context, Task> onRetryAsync, Context context)
{
_onRetryAsync = onRetryAsync;
_context = context;
}
public RetryPolicyState(Func<Exception, Task> onRetryAsync)
: this((Exception exception, Context context) => onRetryAsync(exception), Context.Empty)
{
}
public async Task<bool> CanRetryAsync(Exception ex, CancellationToken ct, bool continueOnCapturedContext)
{
await _onRetryAsync(ex, _context).ConfigureAwait(continueOnCapturedContext);
return true;
}
public RetryPolicyState(Action<Exception, Context> onRetry, Context context)
{
_onRetry = onRetry;
_context = context;
}
public RetryPolicyState(Action<Exception> onRetry)
: this(delegate(Exception exception, Context context) {
onRetry(exception);
}, Context.Empty)
{
}
public bool CanRetry(Exception ex)
{
_onRetry(ex, _context);
return true;
}
}
}