<PackageReference Include="Polly" Version="6.1.2" />

RetrySyntaxAsync

public static class 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.Runtime.CompilerServices; 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, Context> onRetry = delegate { }; return policyBuilder.RetryAsync(retryCount, onRetry); } public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry) { <>c__DisplayClass2_0 <>4__this; return policyBuilder.RetryAsync(1, delegate(Exception outcome, int i, Context ctx) { <>c__DisplayClass2_0.<<RetryAsync>b__0>d stateMachine = default(<>c__DisplayClass2_0.<<RetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.i = i; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync) { return policyBuilder.RetryAsync(1, (Exception outcome, int i, Context ctx) => onRetryAsync(outcome, i)); } public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass4_0 <>4__this; return policyBuilder.RetryAsync(retryCount, delegate(Exception outcome, int i, Context ctx) { <>c__DisplayClass4_0.<<RetryAsync>b__0>d stateMachine = default(<>c__DisplayClass4_0.<<RetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.i = i; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.RetryAsync(retryCount, (Exception outcome, int i, Context ctx) => onRetryAsync(outcome, i)); } 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 (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass8_0 <>4__this; return policyBuilder.RetryAsync(retryCount, delegate(Exception outcome, int i, Context ctx) { <>c__DisplayClass8_0.<<RetryAsync>b__0>d stateMachine = default(<>c__DisplayClass8_0.<<RetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.i = i; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } 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<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateRetryWithCount<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"); <>c__DisplayClass11_0 <>4__this; return policyBuilder.RetryForeverAsync(delegate(Exception outcome, Context ctx) { <>c__DisplayClass11_0.<<RetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass11_0.<<RetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass12_0 <>4__this; return policyBuilder.RetryForeverAsync(delegate(Exception outcome, int i, Context context) { <>c__DisplayClass12_0.<<RetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass12_0.<<RetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.i = i; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.RetryForeverAsync((Exception outcome, Context ctx) => onRetryAsync(outcome)); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.RetryForeverAsync((Exception outcome, int i, Context context) => onRetryAsync(outcome, i)); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass15_0 <>4__this; return policyBuilder.RetryForeverAsync(delegate(Exception outcome, Context ctx) { <>c__DisplayClass15_0.<<RetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass15_0.<<RetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass16_0 <>4__this; return policyBuilder.RetryForeverAsync(delegate(Exception outcome, int i, Context ctx) { <>c__DisplayClass16_0.<<RetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass16_0.<<RetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.i = i; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, Context, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return new RetryPolicy((Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateRetryForever<EmptyStruct>((DelegateResult<EmptyStruct> outcome, Context ctx) => onRetryAsync(outcome.Exception, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates); } public static RetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Context, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return new RetryPolicy((Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateRetryForeverWithCount<EmptyStruct>((DelegateResult<EmptyStruct> outcome, int i, Context ctx) => onRetryAsync(outcome.Exception, i, 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 (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass20_0 <>4__this; return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, delegate(Exception outcome, TimeSpan span, int i, Context ctx) { <>c__DisplayClass20_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass20_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.span = span; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, (Exception outcome, TimeSpan span, int i, Context ctx) => onRetryAsync(outcome, span)); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass22_0 <>4__this; return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, delegate(Exception outcome, TimeSpan span, int i, Context ctx) { <>c__DisplayClass22_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass22_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.span = span; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, (Exception outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome, timespan, ctx)); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass24_0 <>4__this; return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, delegate(Exception outcome, TimeSpan timespan, int i, Context ctx) { <>c__DisplayClass24_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass24_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.timespan = timespan; stateMachine.i = i; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } 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<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateWaitAndRetry<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, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass26_0 <>4__this; return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, delegate(Exception outcome, TimeSpan span, int i, Context ctx) { <>c__DisplayClass26_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass26_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.span = span; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, (Exception outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome, timespan, ctx)); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass28_0 <>4__this; return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, delegate(Exception outcome, TimeSpan timespan, int i, Context ctx) { <>c__DisplayClass28_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass28_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.timespan = timespan; stateMachine.i = i; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, int, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); return policyBuilder.WaitAndRetryAsync(retryCount, (int i, Exception outcome, Context ctx) => sleepDurationProvider(i, ctx), onRetryAsync); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Exception, Context, 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"); return new RetryPolicy((Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateWaitAndRetryWithProvider<EmptyStruct>(retryCount, (int i, DelegateResult<EmptyStruct> outcome, Context ctx) => sleepDurationProvider(i, outcome.Exception, ctx), (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, int, Context> onRetry = delegate { }; return policyBuilder.WaitAndRetryAsync(sleepDurations, onRetry); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass32_0 <>4__this; return policyBuilder.WaitAndRetryAsync(sleepDurations, delegate(Exception outcome, TimeSpan timespan, int i, Context ctx) { <>c__DisplayClass32_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass32_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.timespan = timespan; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryAsync(sleepDurations, (Exception outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome, timespan)); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass34_0 <>4__this; return policyBuilder.WaitAndRetryAsync(sleepDurations, delegate(Exception outcome, TimeSpan timespan, int i, Context ctx) { <>c__DisplayClass34_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass34_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.timespan = timespan; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Func<Exception, TimeSpan, Context, Task> onRetryAsync) { if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryAsync(sleepDurations, (Exception outcome, TimeSpan timespan, int i, Context ctx) => onRetryAsync(outcome, timespan, ctx)); } public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, int, Context> onRetry) { if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass36_0 <>4__this; return policyBuilder.WaitAndRetryAsync(sleepDurations, delegate(Exception outcome, TimeSpan timespan, int i, Context ctx) { <>c__DisplayClass36_0.<<WaitAndRetryAsync>b__0>d stateMachine = default(<>c__DisplayClass36_0.<<WaitAndRetryAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.outcome = outcome; stateMachine.timespan = timespan; stateMachine.i = i; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } 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<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateWaitAndRetry<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, Context, TimeSpan> sleepDurationProvider) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); Action<Exception, TimeSpan, Context> 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 policyBuilder.WaitAndRetryForeverAsync((int retryCount, Context context) => sleepDurationProvider(retryCount), delegate(Exception exception, TimeSpan timespan, Context context) { onRetry(exception, timespan); }); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Action<Exception, int, TimeSpan> onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); if (onRetry == null) throw new ArgumentNullException("onRetry"); return policyBuilder.WaitAndRetryForeverAsync((int retryCount, Context context) => sleepDurationProvider(retryCount), delegate(Exception exception, int i, TimeSpan timespan, Context context) { onRetry(exception, i, timespan); }); } 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 policyBuilder.WaitAndRetryForeverAsync((int retryCount, Context context) => sleepDurationProvider(retryCount), (Exception exception, TimeSpan timespan, Context context) => onRetryAsync(exception, timespan)); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, TimeSpan> sleepDurationProvider, Func<Exception, int, TimeSpan, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return policyBuilder.WaitAndRetryForeverAsync((int retryCount, Context context) => sleepDurationProvider(retryCount), (Exception exception, int i, TimeSpan timespan, Context context) => onRetryAsync(exception, i, timespan)); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, Context> onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass44_0 <>4__this; return policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, delegate(Exception exception, TimeSpan timespan, Context ctx) { <>c__DisplayClass44_0.<<WaitAndRetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass44_0.<<WaitAndRetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.exception = exception; stateMachine.timespan = timespan; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, int, TimeSpan, Context> onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); if (onRetry == null) throw new ArgumentNullException("onRetry"); <>c__DisplayClass45_0 <>4__this; return policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, delegate(Exception exception, int i, TimeSpan timespan, Context ctx) { <>c__DisplayClass45_0.<<WaitAndRetryForeverAsync>b__0>d stateMachine = default(<>c__DisplayClass45_0.<<WaitAndRetryForeverAsync>b__0>d); stateMachine.<>4__this = <>4__this; stateMachine.exception = exception; stateMachine.i = i; stateMachine.timespan = timespan; stateMachine.ctx = ctx; stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>1__state = -1; AsyncTaskMethodBuilder <>t__builder = stateMachine.<>t__builder; <>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; }); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, TimeSpan, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); return policyBuilder.WaitAndRetryForeverAsync((int i, Exception outcome, Context ctx) => sleepDurationProvider(i, ctx), onRetryAsync); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Context, TimeSpan> sleepDurationProvider, Func<Exception, int, TimeSpan, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); return policyBuilder.WaitAndRetryForeverAsync((int i, Exception outcome, Context ctx) => sleepDurationProvider(i, ctx), onRetryAsync); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Exception, Context, 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<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateWaitAndRetryForever<EmptyStruct>((int i, DelegateResult<EmptyStruct> outcome, Context ctx) => sleepDurationProvider(i, outcome.Exception, ctx), (DelegateResult<EmptyStruct> outcome, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, timespan, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates); } public static RetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func<int, Exception, Context, TimeSpan> sleepDurationProvider, Func<Exception, int, TimeSpan, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException("sleepDurationProvider"); if (onRetryAsync == null) throw new ArgumentNullException("onRetryAsync"); return new RetryPolicy((Func<Context, CancellationToken, Task> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => RetryEngine.ImplementationAsync(async delegate(Context ctx, CancellationToken ct) { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, policyBuilder.ExceptionPredicates, PredicateHelper<EmptyStruct>.EmptyResultPredicates, () => new RetryStateWaitAndRetryForeverWithCount<EmptyStruct>((int i, DelegateResult<EmptyStruct> outcome, Context ctx) => sleepDurationProvider(i, outcome.Exception, ctx), (DelegateResult<EmptyStruct> outcome, int i, TimeSpan timespan, Context ctx) => onRetryAsync(outcome.Exception, i, timespan, ctx), context), continueOnCapturedContext), policyBuilder.ExceptionPredicates); } } }