in src/JetBrains.Space.Common/RetryPolicies/ResourceRetryPolicyBase.cs [56:95]
public async Task<TResult> ExecuteAsync<TResult>(
Func<Task<TResult>> handler,
CancellationToken cancellationToken)
{
var previousExceptions = new List<Exception>();
var currentDelay = _initialDelay;
for (var currentRetry = 0; currentRetry < _maxRetries; currentRetry++)
{
try
{
cancellationToken.ThrowIfCancellationRequested();
return await handler();
}
catch (ResourceException exception)
{
if (ShouldRetry(exception))
{
previousExceptions.Add(exception);
await Task.Delay(currentDelay, cancellationToken);
var multipliedDelay = currentDelay * _multiplier;
if (multipliedDelay < _maximumDelay)
{
currentDelay = multipliedDelay;
}
}
else
{
throw;
}
}
}
throw new ResourceException(
$"Failed to execute handler function. The retry limit of {_maxRetries} was reached. " +
$"See the inner {nameof(AggregateException)} for exceptions caught in previous attempts.",
new AggregateException(previousExceptions));
}