RetryStateRetryForeverWithCount<TResult>
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Polly.Retry
{
internal class RetryStateRetryForeverWithCount<TResult> : IRetryPolicyState<TResult>
{
private readonly Func<DelegateResult<TResult>, int, Context, Task> _onRetryAsync;
private int _errorCount;
private readonly Action<DelegateResult<TResult>, int, Context> _onRetry;
private readonly Context _context;
public RetryStateRetryForeverWithCount(Func<DelegateResult<TResult>, int, Context, Task> onRetryAsync, Context context)
{
_onRetryAsync = onRetryAsync;
_context = context;
}
public async Task<bool> CanRetryAsync(DelegateResult<TResult> delegateResult, CancellationToken ct, bool continueOnCapturedContext)
{
if (this._errorCount < 2147483647)
this._errorCount++;
await this._onRetryAsync(delegateResult, this._errorCount, this._context).ConfigureAwait(continueOnCapturedContext);
return true;
}
public RetryStateRetryForeverWithCount(Action<DelegateResult<TResult>, int, Context> onRetry, Context context)
{
_onRetry = onRetry;
_context = context;
}
public bool CanRetry(DelegateResult<TResult> delegateResult, CancellationToken cancellationToken)
{
if (_errorCount < 2147483647)
_errorCount++;
_onRetry(delegateResult, _errorCount, _context);
return true;
}
}
}