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