RetrySyntaxAsync
Fluent API for defining a Retry Policy.
using Polly.Retry;
using Polly.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Polly
{
public static class RetrySyntaxAsync
{
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder)
{
return policyBuilder.RetryAsync(1);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount)
{
Action<Exception, int> onRetry = delegate {
};
return policyBuilder.RetryAsync(retryCount, onRetry);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry)
{
return policyBuilder.RetryAsync(1, onRetry);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int> onRetry)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithCount<EmptyStruct>(retryCount, async delegate(DelegateResult<EmptyStruct> outcome, int i, Context ctx) {
onRetry(outcome.Exception, i);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Task> onRetryAsync)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithCount<EmptyStruct>(retryCount, (DelegateResult<EmptyStruct> outcome, int i, Context ctx) => onRetryAsync(outcome.Exception, i), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry)
{
return policyBuilder.RetryAsync(1, onRetry);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Context, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int, Context> onRetry)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithCount<EmptyStruct>(retryCount, async delegate(DelegateResult<EmptyStruct> outcome, int i, Context c) {
onRetry(outcome.Exception, i, c);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Context, Task> onRetryAsync)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithCount<EmptyStruct>(retryCount, (DelegateResult<EmptyStruct> outcome, int i, Context ctx) => onRetryAsync(outcome.Exception, i, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder)
{
Action<Exception> onRetry = delegate {
};
return policyBuilder.RetryForeverAsync(onRetry);
}
public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception> onRetry)
{
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyState<EmptyStruct>(async delegate(DelegateResult<EmptyStruct> outcome, Context ctx) {
onRetry(outcome.Exception);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Task> onRetryAsync)
{
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyState<EmptyStruct>((DelegateResult<EmptyStruct> outcome, Context ctx) => onRetryAsync(outcome.Exception), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception, Context> onRetry)
{
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyState<EmptyStruct>(async delegate(DelegateResult<EmptyStruct> outcome, Context c) {
onRetry(outcome.Exception, c);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Context, Task> onRetryAsync)
{
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyState<EmptyStruct>((DelegateResult<EmptyStruct> outcome, Context ctx) => onRetryAsync(outcome.Exception, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider)
{
Action<Exception, TimeSpan> onRetry = delegate {
};
return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, onRetry);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Task> onRetryAsync)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan, ctx);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, int i, Context ctx) {
onRetry(outcome.Exception, timespan, i, ctx);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync)
{
if (retryCount < 0)
throw new ArgumentOutOfRangeException("retryCount", "Value must be greater than or equal to zero.");
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
IEnumerable<TimeSpan> sleepDurations = Enumerable.Range(1, retryCount).Select(sleepDurationProvider);
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome.Exception, timespan, i, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations)
{
Action<Exception, TimeSpan> onRetry = delegate {
};
return policyBuilder.WaitAndRetryAsync(sleepDurations, onRetry);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan> onRetry)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Task> onRetryAsync)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, Context> onRetry)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan, ctx);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, int, Context> onRetry)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, int i, Context ctx) {
onRetry(outcome.Exception, timespan, i, ctx);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Context, Task> onRetryAsync)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync)
{
if (sleepDurations == null)
throw new ArgumentNullException("sleepDurations");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleep<EmptyStruct>(sleepDurations, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome.Exception, timespan, i, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider)
{
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
Action<Exception, TimeSpan> onRetry = delegate {
};
return policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, onRetry);
}
public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan> onRetry)
{
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleepDurationProvider<EmptyStruct>(sleepDurationProvider, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Task> onRetryAsync)
{
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleepDurationProvider<EmptyStruct>(sleepDurationProvider, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry)
{
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetry == null)
throw new ArgumentNullException("onRetry");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleepDurationProvider<EmptyStruct>(sleepDurationProvider, async delegate(DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) {
onRetry(outcome.Exception, timespan, ctx);
}, context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync)
{
if (sleepDurationProvider == null)
throw new ArgumentNullException("sleepDurationProvider");
if (onRetryAsync == null)
throw new ArgumentNullException("onRetryAsync");
return new RetryPolicy((Func<CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(CancellationToken ct) {
await action(ct).ConfigureAwait(continueOnCapturedContext);
return EmptyStruct.Instance;
}, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryPolicyStateWithSleepDurationProvider<EmptyStruct>(sleepDurationProvider, (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates);
}
}
}