diff --git a/src/Polly/AsyncPolicy.GenericImplementation.cs b/src/Polly/AsyncPolicy.GenericImplementation.cs index 090c09b479..809e7781c7 100644 --- a/src/Polly/AsyncPolicy.GenericImplementation.cs +++ b/src/Polly/AsyncPolicy.GenericImplementation.cs @@ -14,6 +14,5 @@ protected abstract Task ImplementationAsync( Func> action, Context context, CancellationToken cancellationToken, - bool continueOnCapturedContext - ); + bool continueOnCapturedContext); } diff --git a/src/Polly/AsyncPolicy.NonGenericImplementation.cs b/src/Polly/AsyncPolicy.NonGenericImplementation.cs index db23da1af2..f54acfcdda 100644 --- a/src/Polly/AsyncPolicy.NonGenericImplementation.cs +++ b/src/Polly/AsyncPolicy.NonGenericImplementation.cs @@ -34,6 +34,5 @@ protected abstract Task ImplementationAsync( Func> action, Context context, CancellationToken cancellationToken, - bool continueOnCapturedContext - ); + bool continueOnCapturedContext); } diff --git a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs index bb4c28e04f..1476fcb587 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs @@ -17,6 +17,7 @@ internal static async Task ImplementationAsync( await onBulkheadRejectedAsync(context).ConfigureAwait(continueOnCapturedContext); throw new BulkheadRejectedException(); } + try { await maxParallelizationSemaphore.WaitAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext); diff --git a/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs b/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs index 4cac100eb2..36f904f538 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs @@ -66,7 +66,6 @@ public static AsyncBulkheadPolicy BulkheadAsync( return new AsyncBulkheadPolicy( maxParallelization, maxQueuingActions, - onBulkheadRejectedAsync - ); + onBulkheadRejectedAsync); } } diff --git a/src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs b/src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs index 8e764dd00d..f3335538c1 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs @@ -63,7 +63,6 @@ public static AsyncBulkheadPolicy BulkheadAsync(int maxParalle return new AsyncBulkheadPolicy( maxParallelization, maxQueuingActions, - onBulkheadRejectedAsync - ); + onBulkheadRejectedAsync); } } diff --git a/src/Polly/Bulkhead/BulkheadSyntax.cs b/src/Polly/Bulkhead/BulkheadSyntax.cs index 5bfae79ce9..ed928e105a 100644 --- a/src/Polly/Bulkhead/BulkheadSyntax.cs +++ b/src/Polly/Bulkhead/BulkheadSyntax.cs @@ -63,7 +63,6 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi return new BulkheadPolicy( maxParallelization, maxQueuingActions, - onBulkheadRejected - ); + onBulkheadRejected); } } diff --git a/src/Polly/Bulkhead/BulkheadTResultSyntax.cs b/src/Polly/Bulkhead/BulkheadTResultSyntax.cs index f493edb695..a8e43ae824 100644 --- a/src/Polly/Bulkhead/BulkheadTResultSyntax.cs +++ b/src/Polly/Bulkhead/BulkheadTResultSyntax.cs @@ -63,7 +63,6 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, return new BulkheadPolicy( maxParallelization, maxQueuingActions, - onBulkheadRejected - ); + onBulkheadRejected); } } diff --git a/src/Polly/Caching/AsyncCacheEngine.cs b/src/Polly/Caching/AsyncCacheEngine.cs index 4ef9dcc1c0..170b28c14f 100644 --- a/src/Polly/Caching/AsyncCacheEngine.cs +++ b/src/Polly/Caching/AsyncCacheEngine.cs @@ -37,6 +37,7 @@ internal static async Task ImplementationAsync( valueFromCache = default; onCacheGetError?.Invoke(context, cacheKey, ex); } + if (cacheHit) { onCacheGet(context, cacheKey); diff --git a/src/Polly/Caching/AsyncSerializingCacheProvider.cs b/src/Polly/Caching/AsyncSerializingCacheProvider.cs index 0a12b08864..4d40c1a409 100644 --- a/src/Polly/Caching/AsyncSerializingCacheProvider.cs +++ b/src/Polly/Caching/AsyncSerializingCacheProvider.cs @@ -55,8 +55,7 @@ public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cance _serializer.Serialize(value), ttl, cancellationToken, - continueOnCapturedContext - ); + continueOnCapturedContext); } /// @@ -114,6 +113,5 @@ public Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken canc _serializer.Serialize(value), ttl, cancellationToken, - continueOnCapturedContext - ); + continueOnCapturedContext); } diff --git a/src/Polly/Caching/CacheEngine.cs b/src/Polly/Caching/CacheEngine.cs index ca2a1a469e..dca2d9d4af 100644 --- a/src/Polly/Caching/CacheEngine.cs +++ b/src/Polly/Caching/CacheEngine.cs @@ -36,6 +36,7 @@ internal static TResult Implementation( valueFromCache = default; onCacheGetError?.Invoke(context, cacheKey, ex); } + if (cacheHit) { onCacheGet(context, cacheKey); diff --git a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs index 31a5a43c15..1b865a9e5f 100644 --- a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs +++ b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerSyntax.cs @@ -37,8 +37,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -72,8 +71,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), - _ => onReset() - ); + _ => onReset()); /// /// The circuit will break if, within any timeslice of duration , the proportion of actions resulting in a handled exception exceeds , provided also that the number of actions through the circuit in the timeslice is at least . @@ -108,8 +106,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -146,8 +143,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -184,8 +180,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol durationOfBreak, (exception, _, timespan, context) => onBreak(exception, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -240,7 +235,6 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this PolicyBuilder pol onHalfOpen); return new CircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs index 7375dd9779..d34c57e4af 100644 --- a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs @@ -37,8 +37,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -72,8 +71,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), - _ => onReset() - ); + _ => onReset()); /// /// The circuit will break if, within any timeslice of duration , the proportion of actions resulting in a handled exception or result exceeds , provided also that the number of actions through the circuit in the timeslice is at least . @@ -108,8 +106,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -146,8 +143,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -185,8 +181,7 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this durationOfBreak, (outcome, _, timespan, context) => onBreak(outcome, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -240,9 +235,9 @@ public static CircuitBreakerPolicy AdvancedCircuitBreaker(this onBreak, onReset, onHalfOpen); + return new CircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/AdvancedCircuitController.cs b/src/Polly/CircuitBreaker/AdvancedCircuitController.cs index 8980cc4698..3813c1de99 100644 --- a/src/Polly/CircuitBreaker/AdvancedCircuitController.cs +++ b/src/Polly/CircuitBreaker/AdvancedCircuitController.cs @@ -16,8 +16,7 @@ public AdvancedCircuitController( TimeSpan durationOfBreak, Action, CircuitState, TimeSpan, Context> onBreak, Action onReset, - Action onHalfOpen - ) + Action onHalfOpen) : base(durationOfBreak, onBreak, onReset, onHalfOpen) { _metrics = samplingDuration.Ticks < ResolutionOfCircuitTimer * NumberOfWindows @@ -85,6 +84,7 @@ public override void OnActionFailure(DelegateResult outcome, Context co { Break_NeedsLock(context); } + break; case CircuitState.Open: diff --git a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerSyntax.cs b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerSyntax.cs index bde095ec5a..f9d25e21f4 100644 --- a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerSyntax.cs @@ -38,8 +38,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -74,8 +73,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -112,8 +110,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -150,8 +147,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -188,8 +184,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB durationOfBreak, (exception, _, timespan, context) => onBreak(exception, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -242,9 +237,9 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync(this PolicyB (outcome, state, timespan, context) => onBreak(outcome.Exception, state, timespan, context), onReset, onHalfOpen); + return new AsyncCircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs index 6521554fe2..03fafcb581 100644 --- a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs @@ -37,8 +37,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync @@ -73,8 +72,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync onBreak(outcome, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -106,13 +104,13 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync AdvancedCircuitBreakerAsync(this PolicyBuilder policyBuilder, double failureThreshold, TimeSpan samplingDuration, int minimumThroughput, TimeSpan durationOfBreak, Action, TimeSpan, Context> onBreak, Action onReset) { Action doNothingOnHalfOpen = () => { }; + return policyBuilder.AdvancedCircuitBreakerAsync( failureThreshold, samplingDuration, minimumThroughput, durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -149,8 +147,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync onBreak(outcome, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -187,8 +184,7 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync onBreak(outcome, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -241,9 +237,9 @@ public static AsyncCircuitBreakerPolicy AdvancedCircuitBreakerAsync( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs index 4988a3819f..e8d7ad4691 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs @@ -9,8 +9,7 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuitBreakerPolicy internal AsyncCircuitBreakerPolicy( PolicyBuilder policyBuilder, - ICircuitController breakerController - ) + ICircuitController breakerController) : base(policyBuilder) => _breakerController = breakerController; @@ -64,8 +63,7 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuit internal AsyncCircuitBreakerPolicy( PolicyBuilder policyBuilder, - ICircuitController breakerController - ) + ICircuitController breakerController) : base(policyBuilder) => _breakerController = breakerController; diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs index f2b5d848d2..5156eccb7c 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs @@ -32,8 +32,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p exceptionsAllowedBeforeBreaking, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -63,8 +62,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p exceptionsAllowedBeforeBreaking, durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -91,13 +89,13 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder policyBuilder, int exceptionsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action onBreak, Action onReset) { Action doNothingOnHalfOpen = () => { }; + return policyBuilder.CircuitBreakerAsync( exceptionsAllowedBeforeBreaking, durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -129,8 +127,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -162,8 +159,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p durationOfBreak, (exception, _, timespan, context) => onBreak(exception, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -204,10 +200,10 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p (outcome, state, timespan, context) => onBreak(outcome.Exception, state, timespan, context), onReset, onHalfOpen); + return new AsyncCircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs index 3ccdf8d39f..2c1805aca2 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs @@ -32,8 +32,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th handledEventsAllowedBeforeBreaking, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -63,8 +62,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th handledEventsAllowedBeforeBreaking, durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -91,13 +89,13 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder policyBuilder, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action, TimeSpan, Context> onBreak, Action onReset) { Action doNothingOnHalfOpen = () => { }; + return policyBuilder.CircuitBreakerAsync( handledEventsAllowedBeforeBreaking, durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -129,8 +127,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -162,8 +159,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th durationOfBreak, (outcome, _, timespan, context) => onBreak(outcome, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -204,10 +200,10 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th onBreak, onReset, onHalfOpen); + return new AsyncCircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs b/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs index 87fe9b4d90..9f378d6d21 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs @@ -45,6 +45,7 @@ internal static TResult Implementation( { ExceptionDispatchInfo.Capture(handledException).Throw(); } + throw; } } diff --git a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs index d83e260a9a..138185ae78 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs @@ -9,8 +9,7 @@ public class CircuitBreakerPolicy : Policy, ICircuitBreakerPolicy internal CircuitBreakerPolicy( PolicyBuilder policyBuilder, - ICircuitController breakerController - ) + ICircuitController breakerController) : base(policyBuilder) => _breakerController = breakerController; @@ -62,8 +61,7 @@ public class CircuitBreakerPolicy : Policy, ICircuitBreakerPol internal CircuitBreakerPolicy( PolicyBuilder policyBuilder, - ICircuitController breakerController - ) + ICircuitController breakerController) : base(policyBuilder) => _breakerController = breakerController; diff --git a/src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs b/src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs index 7f67a6b159..1e600ad19a 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs @@ -30,12 +30,11 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild Action doNothingOnBreak = (_, _) => { }; Action doNothingOnReset = () => { }; - return policyBuilder.CircuitBreaker - (exceptionsAllowedBeforeBreaking, + return policyBuilder.CircuitBreaker( + exceptionsAllowedBeforeBreaking, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -65,8 +64,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild exceptionsAllowedBeforeBreaking, durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -93,12 +91,12 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuilder, int exceptionsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action onBreak, Action onReset) { Action doNothingOnHalfOpen = () => { }; + return policyBuilder.CircuitBreaker(exceptionsAllowedBeforeBreaking, durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -130,8 +128,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild durationOfBreak, (exception, timespan, _) => onBreak(exception, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -163,8 +160,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild durationOfBreak, (exception, _, timespan, context) => onBreak(exception, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -205,9 +201,9 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuild (outcome, state, timespan, context) => onBreak(outcome.Exception, state, timespan, context), onReset, onHalfOpen); + return new CircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs index 7556a0005b..b8ae019780 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs @@ -30,12 +30,11 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB Action, TimeSpan> doNothingOnBreak = (_, _) => { }; Action doNothingOnReset = () => { }; - return policyBuilder.CircuitBreaker - (handledEventsAllowedBeforeBreaking, + return policyBuilder.CircuitBreaker( + handledEventsAllowedBeforeBreaking, durationOfBreak, doNothingOnBreak, - doNothingOnReset - ); + doNothingOnReset); } /// @@ -65,8 +64,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB handledEventsAllowedBeforeBreaking, durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), - _ => onReset() - ); + _ => onReset()); /// /// Builds a that will function like a Circuit Breaker. @@ -93,12 +91,12 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuilder, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action, TimeSpan, Context> onBreak, Action onReset) { Action doNothingOnHalfOpen = () => { }; + return policyBuilder.CircuitBreaker(handledEventsAllowedBeforeBreaking, durationOfBreak, onBreak, onReset, - doNothingOnHalfOpen - ); + doNothingOnHalfOpen); } /// @@ -130,8 +128,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB durationOfBreak, (outcome, timespan, _) => onBreak(outcome, timespan), _ => onReset(), - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -163,8 +160,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB durationOfBreak, (outcome, _, timespan, context) => onBreak(outcome, timespan, context), onReset, - onHalfOpen - ); + onHalfOpen); /// /// Builds a that will function like a Circuit Breaker. @@ -205,9 +201,9 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB onBreak, onReset, onHalfOpen); + return new CircuitBreakerPolicy( policyBuilder, - breakerController - ); + breakerController); } } diff --git a/src/Polly/CircuitBreaker/CircuitStateController.cs b/src/Polly/CircuitBreaker/CircuitStateController.cs index be7f8f5cdf..4d24444a82 100644 --- a/src/Polly/CircuitBreaker/CircuitStateController.cs +++ b/src/Polly/CircuitBreaker/CircuitStateController.cs @@ -117,6 +117,7 @@ protected bool PermitHalfOpenCircuitTest() { return false; } + // It's time to permit a / another trial call in the half-open state ... // ... but to prevent race conditions/multiple calls, we have to ensure only _one_ thread wins the race to own this next call. return Interlocked.CompareExchange(ref _blockedTill, SystemClock.UtcNow().Ticks + _durationOfBreak.Ticks, currentlyBlockedUntil) == currentlyBlockedUntil; diff --git a/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs b/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs index 331dd9f011..2dc1cafb3b 100644 --- a/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs +++ b/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs @@ -10,8 +10,7 @@ public ConsecutiveCountCircuitController( TimeSpan durationOfBreak, Action, CircuitState, TimeSpan, Context> onBreak, Action onReset, - Action onHalfOpen - ) + Action onHalfOpen) : base(durationOfBreak, onBreak, onReset, onHalfOpen) => _exceptionsAllowedBeforeBreaking = exceptionsAllowedBeforeBreaking; @@ -63,6 +62,7 @@ public override void OnActionFailure(DelegateResult outcome, Context co { Break_NeedsLock(context); } + break; case CircuitState.Open: diff --git a/src/Polly/CircuitBreaker/SingleHealthMetrics.cs b/src/Polly/CircuitBreaker/SingleHealthMetrics.cs index c570f07d9d..dc06e4d9bc 100644 --- a/src/Polly/CircuitBreaker/SingleHealthMetrics.cs +++ b/src/Polly/CircuitBreaker/SingleHealthMetrics.cs @@ -33,6 +33,7 @@ private HealthCount ActualiseCurrentMetric_NeedsLock() StartedAt = now }; } + return _current; } } diff --git a/src/Polly/Fallback/AsyncFallbackPolicy.cs b/src/Polly/Fallback/AsyncFallbackPolicy.cs index 9765dd03b4..6d9ef1d5ff 100644 --- a/src/Polly/Fallback/AsyncFallbackPolicy.cs +++ b/src/Polly/Fallback/AsyncFallbackPolicy.cs @@ -60,8 +60,7 @@ public class AsyncFallbackPolicy : AsyncPolicy, IFallbackPolic internal AsyncFallbackPolicy( PolicyBuilder policyBuilder, Func, Context, Task> onFallbackAsync, - Func, Context, CancellationToken, Task> fallbackAction - ) + Func, Context, CancellationToken, Task> fallbackAction) : base(policyBuilder) { _onFallbackAsync = onFallbackAsync ?? throw new ArgumentNullException(nameof(onFallbackAsync)); diff --git a/src/Polly/Fallback/AsyncFallbackSyntax.cs b/src/Polly/Fallback/AsyncFallbackSyntax.cs index 2563fb07be..fc92303b08 100644 --- a/src/Polly/Fallback/AsyncFallbackSyntax.cs +++ b/src/Polly/Fallback/AsyncFallbackSyntax.cs @@ -21,8 +21,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder Func doNothing = _ => TaskHelper.EmptyTask; return policyBuilder.FallbackAsync( fallbackAction, - doNothing - ); + doNothing); } /// @@ -41,8 +40,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder return policyBuilder.FallbackAsync( (_, _, ct) => fallbackAction(ct), - (outcome, _) => onFallbackAsync(outcome) - ); + (outcome, _) => onFallbackAsync(outcome)); } /// @@ -96,8 +94,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui Func, Task> doNothing = _ => TaskHelper.EmptyTask; return policyBuilder.FallbackAsync( _ => Task.FromResult(fallbackValue), - doNothing - ); + doNothing); } /// @@ -114,8 +111,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui Func, Task> doNothing = _ => TaskHelper.EmptyTask; return policyBuilder.FallbackAsync( fallbackAction, - doNothing - ); + doNothing); } /// @@ -132,8 +128,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui return policyBuilder.FallbackAsync( (_, _, _) => Task.FromResult(fallbackValue), - (outcome, _) => onFallbackAsync(outcome) - ); + (outcome, _) => onFallbackAsync(outcome)); } /// @@ -152,8 +147,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui return policyBuilder.FallbackAsync( (_, _, ct) => fallbackAction(ct), - (outcome, _) => onFallbackAsync(outcome) - ); + (outcome, _) => onFallbackAsync(outcome)); } /// @@ -170,8 +164,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui return policyBuilder.FallbackAsync( (_, _, _) => Task.FromResult(fallbackValue), - onFallbackAsync - ); + onFallbackAsync); } /// diff --git a/src/Polly/Fallback/FallbackPolicy.cs b/src/Polly/Fallback/FallbackPolicy.cs index 7581427079..56fe7c91e7 100644 --- a/src/Polly/Fallback/FallbackPolicy.cs +++ b/src/Polly/Fallback/FallbackPolicy.cs @@ -56,8 +56,7 @@ public class FallbackPolicy : Policy, IFallbackPolicy internal FallbackPolicy( PolicyBuilder policyBuilder, Action, Context> onFallback, - Func, Context, CancellationToken, TResult> fallbackAction - ) + Func, Context, CancellationToken, TResult> fallbackAction) : base(policyBuilder) { _onFallback = onFallback ?? throw new ArgumentNullException(nameof(onFallback)); diff --git a/src/Polly/Policy.SyncGenericImplementation.cs b/src/Polly/Policy.SyncGenericImplementation.cs index 51121e6d28..5567208f5a 100644 --- a/src/Polly/Policy.SyncGenericImplementation.cs +++ b/src/Polly/Policy.SyncGenericImplementation.cs @@ -12,6 +12,5 @@ public abstract partial class Policy protected abstract TResult Implementation( Func action, Context context, - CancellationToken cancellationToken - ); + CancellationToken cancellationToken); } diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj index fc36ee1af4..03095db30a 100644 --- a/src/Polly/Polly.csproj +++ b/src/Polly/Polly.csproj @@ -6,10 +6,10 @@ Library 70 true - $(NoWarn);IDE0011;SA1501;S103;IDE0055;SA1111;S3872;SA1402;SA1513;SA1414;S3215;S2955 - $(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;SA1121;CA1000;CA1063;CA1031;CA1051 + $(NoWarn);IDE0011;SA1501;S103;IDE0055;S3872;SA1402;SA1414;S3215;S2955 + $(NoWarn);IDE1006;CA1062;S107;CA1068;S4039;CA1000;CA1063;CA1031;CA1051 $(NoWarn);SA1612;CA2211;S2223;CA1032;CA1815;CA1816;S4457;SA1615;S109;SA1618;CA1033 - $(NoWarn);SA1515;S4023;CA1010;S2681;S3442;S3880;CA1064;SA1110;SA1203;SA1649;SA1625;SA1623;SA1118 + $(NoWarn);SA1515;S4023;CA1010;S2681;S3442;S3880;CA1064;SA1203;SA1649;SA1625;SA1623;SA1118 $(NoWarn);S3253;S3971;S6605;CA1724;CA1716;SA1108;CA1710;S4049;S3246 $(NoWarn);CA1805;CA1821 diff --git a/src/Polly/RateLimit/AsyncRateLimitEngine.cs b/src/Polly/RateLimit/AsyncRateLimitEngine.cs index 6a77299016..0c31e6fcda 100644 --- a/src/Polly/RateLimit/AsyncRateLimitEngine.cs +++ b/src/Polly/RateLimit/AsyncRateLimitEngine.cs @@ -10,8 +10,7 @@ internal static async Task ImplementationAsync( Func> action, Context context, CancellationToken cancellationToken, - bool continueOnCapturedContext - ) + bool continueOnCapturedContext) { (bool permit, TimeSpan retryAfter) = rateLimiter.PermitExecution(); diff --git a/src/Polly/RateLimit/RateLimitEngine.cs b/src/Polly/RateLimit/RateLimitEngine.cs index 247e6572fb..43de04c7b3 100644 --- a/src/Polly/RateLimit/RateLimitEngine.cs +++ b/src/Polly/RateLimit/RateLimitEngine.cs @@ -9,8 +9,7 @@ internal static TResult Implementation( Func? retryAfterFactory, Func action, Context context, - CancellationToken cancellationToken - ) + CancellationToken cancellationToken) { (bool permit, TimeSpan retryAfter) = rateLimiter.PermitExecution(); diff --git a/src/Polly/Retry/AsyncRetryEngine.cs b/src/Polly/Retry/AsyncRetryEngine.cs index 57ae503de1..da3844a140 100644 --- a/src/Polly/Retry/AsyncRetryEngine.cs +++ b/src/Polly/Retry/AsyncRetryEngine.cs @@ -10,7 +10,7 @@ internal static async Task ImplementationAsync( ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates shouldRetryResultPredicates, Func, TimeSpan, int, Context, Task> onRetryAsync, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, Func, Context, TimeSpan>? sleepDurationProvider = null, bool continueOnCapturedContext = false) diff --git a/src/Polly/Retry/AsyncRetryPolicy.cs b/src/Polly/Retry/AsyncRetryPolicy.cs index 721f9f5caa..1baa7ea197 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -13,10 +13,9 @@ public class AsyncRetryPolicy : AsyncPolicy, IRetryPolicy internal AsyncRetryPolicy( PolicyBuilder policyBuilder, Func onRetryAsync, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable sleepDurationsEnumerable = null, - Func sleepDurationProvider = null - ) + Func sleepDurationProvider = null) : base(policyBuilder) { _permittedRetryCount = permittedRetryCount; @@ -41,8 +40,7 @@ protected override Task ImplementationAsync(Func _sleepDurationProvider(retryCount, outcome.Exception, ctx) : (Func, Context, TimeSpan>) null, - continueOnCapturedContext - ); + continueOnCapturedContext); } /// @@ -58,10 +56,9 @@ public class AsyncRetryPolicy : AsyncPolicy, IRetryPolicy policyBuilder, Func, TimeSpan, int, Context, Task> onRetryAsync, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable sleepDurationsEnumerable = null, - Func, Context, TimeSpan> sleepDurationProvider = null - ) + Func, Context, TimeSpan> sleepDurationProvider = null) : base(policyBuilder) { _permittedRetryCount = permittedRetryCount; @@ -84,7 +81,6 @@ protected override Task ImplementationAsync(FunconRetry public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action onRetry) { - return policyBuilder.RetryAsync(1, #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, _) => onRetry(outcome, i) + return policyBuilder.RetryAsync(1, + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -67,12 +66,10 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action onRetry) { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - - return policyBuilder.RetryAsync(retryCount, #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, _) => onRetry(outcome, i) + return policyBuilder.RetryAsync(retryCount, + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -128,11 +125,10 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryAsync(retryCount, #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx) + return policyBuilder.RetryAsync(retryCount, + onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -153,8 +149,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int return new AsyncRetryPolicy( policyBuilder, (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx), - retryCount - ); + retryCount); } /// @@ -181,11 +176,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (Exception outcome, Context _) => onRetry(outcome) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (Exception outcome, Context _) => onRetry(outcome)); #pragma warning restore 1998 - ); } /// @@ -200,11 +194,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, _) => onRetry(outcome, i) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -249,11 +242,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, ctx) => onRetry(outcome, ctx) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, ctx) => onRetry(outcome, ctx)); #pragma warning restore 1998 - ); } /// @@ -268,11 +260,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -289,8 +280,7 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde return new AsyncRetryPolicy( policyBuilder, - (outcome, _, _, ctx) => onRetryAsync(outcome, ctx) - ); + (outcome, _, _, ctx) => onRetryAsync(outcome, ctx)); } /// @@ -307,8 +297,7 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilde return new AsyncRetryPolicy( policyBuilder, - (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx) - ); + (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx)); } /// @@ -348,13 +337,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, _) => onRetry(outcome, span) + onRetryAsync: async (outcome, span, _, _) => onRetry(outcome, span)); #pragma warning restore 1998 - ); } /// @@ -378,13 +366,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetryAsync == null) throw new ArgumentNullException(nameof(onRetryAsync)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: (outcome, span, _, _) => onRetryAsync(outcome, span) + onRetryAsync: (outcome, span, _, _) => onRetryAsync(outcome, span)); #pragma warning restore 1998 - ); } /// @@ -409,13 +396,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx) + onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); #pragma warning restore 1998 - ); } /// @@ -443,8 +429,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -468,13 +453,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -508,8 +492,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde policyBuilder, onRetryAsync, retryCount, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -534,13 +517,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx) + onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); #pragma warning restore 1998 - ); } /// @@ -568,8 +550,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -593,13 +574,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -657,8 +637,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde policyBuilder, onRetryAsync, retryCount, - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } /// @@ -695,12 +674,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, _, _) => onRetry(outcome, timespan) + onRetryAsync: async (outcome, timespan, _, _) => onRetry(outcome, timespan)); #pragma warning restore 1998 - ); } /// @@ -724,8 +702,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde return policyBuilder.WaitAndRetryAsync( sleepDurations, - onRetryAsync: (outcome, timespan, _, _) => onRetryAsync(outcome, timespan) - ); + onRetryAsync: (outcome, timespan, _, _) => onRetryAsync(outcome, timespan)); } /// @@ -747,12 +724,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, _, ctx) => onRetry(outcome, timespan, ctx) + onRetryAsync: async (outcome, timespan, _, ctx) => onRetry(outcome, timespan, ctx)); #pragma warning restore 1998 - ); } /// @@ -776,8 +752,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde return policyBuilder.WaitAndRetryAsync( sleepDurations, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -799,12 +774,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -830,8 +804,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilde return new AsyncRetryPolicy( policyBuilder, onRetryAsync, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -889,8 +862,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, timespan, _) => onRetry(exception, timespan) - ); + (exception, timespan, _) => onRetry(exception, timespan)); } /// @@ -912,8 +884,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, i, timespan, _) => onRetry(exception, i, timespan) - ); + (exception, i, timespan, _) => onRetry(exception, i, timespan)); } /// @@ -935,8 +906,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, timespan, _) => onRetryAsync(exception, timespan) - ); + (exception, timespan, _) => onRetryAsync(exception, timespan)); } /// @@ -958,8 +928,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, i, timespan, _) => onRetryAsync(exception, i, timespan) - ); + (exception, i, timespan, _) => onRetryAsync(exception, i, timespan)); } /// @@ -979,12 +948,11 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryForeverAsync( sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - async (exception, timespan, ctx) => onRetry(exception, timespan, ctx) + async (exception, timespan, ctx) => onRetry(exception, timespan, ctx)); #pragma warning restore 1998 - ); } /// @@ -1004,12 +972,11 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryForeverAsync( sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - async (exception, i, timespan, ctx) => onRetry(exception, i, timespan, ctx) + async (exception, i, timespan, ctx) => onRetry(exception, i, timespan, ctx)); #pragma warning restore 1998 - ); } /// @@ -1029,8 +996,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); return policyBuilder.WaitAndRetryForeverAsync( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetryAsync - ); + onRetryAsync); } /// @@ -1048,10 +1014,10 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Func onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForeverAsync( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetryAsync - ); + onRetryAsync); } /// @@ -1097,8 +1063,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder polic return new AsyncRetryPolicy( policyBuilder, (exception, timespan, i, ctx) => onRetryAsync(exception, i, timespan, ctx), - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } } diff --git a/src/Polly/Retry/AsyncRetryTResultSyntax.cs b/src/Polly/Retry/AsyncRetryTResultSyntax.cs index bc1595c0d4..5845834d98 100644 --- a/src/Polly/Retry/AsyncRetryTResultSyntax.cs +++ b/src/Polly/Retry/AsyncRetryTResultSyntax.cs @@ -36,11 +36,10 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilderonRetry public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action, int> onRetry) { - return policyBuilder.RetryAsync(1, #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, _) => onRetry(outcome, i) + return policyBuilder.RetryAsync(1, + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -68,11 +67,10 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder onRetry(outcome, i) + return policyBuilder.RetryAsync(retryCount, + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -128,11 +126,10 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder onRetry(outcome, i, ctx) + return policyBuilder.RetryAsync(retryCount, + onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -153,8 +150,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder( policyBuilder, (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx), - retryCount - ); + retryCount); } /// @@ -181,11 +177,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (DelegateResult outcome, Context _) => onRetry(outcome) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (DelegateResult outcome, Context _) => onRetry(outcome)); #pragma warning restore 1998 - ); } /// @@ -200,11 +195,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, _) => onRetry(outcome, i) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, i, _) => onRetry(outcome, i)); #pragma warning restore 1998 - ); } /// @@ -249,11 +243,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, ctx) => onRetry(outcome, ctx) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, ctx) => onRetry(outcome, ctx)); #pragma warning restore 1998 - ); } /// @@ -268,11 +261,10 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); - return policyBuilder.RetryForeverAsync( #pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx) + return policyBuilder.RetryForeverAsync( + onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -289,8 +281,7 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu return new AsyncRetryPolicy( policyBuilder, - (outcome, _, _, ctx) => onRetryAsync(outcome, ctx) - ); + (outcome, _, _, ctx) => onRetryAsync(outcome, ctx)); } /// @@ -307,8 +298,7 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu return new AsyncRetryPolicy( policyBuilder, - (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx) - ); + (outcome, _, i, ctx) => onRetryAsync(outcome, i, ctx)); } /// @@ -349,13 +339,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, _) => onRetry(outcome, span) + onRetryAsync: async (outcome, span, _, _) => onRetry(outcome, span)); #pragma warning restore 1998 - ); } /// @@ -379,13 +368,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetryAsync == null) throw new ArgumentNullException(nameof(onRetryAsync)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: (outcome, span, _, _) => onRetryAsync(outcome, span) + onRetryAsync: (outcome, span, _, _) => onRetryAsync(outcome, span)); #pragma warning restore 1998 - ); } /// @@ -410,13 +398,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx) + onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); #pragma warning restore 1998 - ); } /// @@ -443,8 +430,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -468,13 +454,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -508,8 +493,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu policyBuilder, onRetryAsync, retryCount, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -534,13 +518,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx) + onRetryAsync: async (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); #pragma warning restore 1998 - ); } /// @@ -567,8 +550,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -592,13 +574,12 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( retryCount, sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -622,6 +603,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu Func sleepDurationProvider, Func, TimeSpan, int, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryAsync( retryCount, (i, _, ctx) => sleepDurationProvider(i, ctx), @@ -656,8 +638,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu policyBuilder, onRetryAsync, retryCount, - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } /// @@ -694,12 +675,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, _, _) => onRetry(outcome, timespan) + onRetryAsync: async (outcome, timespan, _, _) => onRetry(outcome, timespan)); #pragma warning restore 1998 - ); } /// @@ -723,8 +703,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu return policyBuilder.WaitAndRetryAsync( sleepDurations, - onRetryAsync: (outcome, timespan, _, _) => onRetryAsync(outcome, timespan) - ); + onRetryAsync: (outcome, timespan, _, _) => onRetryAsync(outcome, timespan)); } /// @@ -746,13 +725,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, _, ctx) => onRetry(outcome, timespan, ctx) + onRetryAsync: async (outcome, timespan, _, ctx) => onRetry(outcome, timespan, ctx)); #pragma warning restore 1998 - ); - } /// @@ -776,8 +753,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu return policyBuilder.WaitAndRetryAsync( sleepDurations, - onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx) - ); + onRetryAsync: (outcome, timespan, _, ctx) => onRetryAsync(outcome, timespan, ctx)); } /// @@ -799,12 +775,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryAsync( sleepDurations, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx) + onRetryAsync: async (outcome, timespan, i, ctx) => onRetry(outcome, timespan, i, ctx)); #pragma warning restore 1998 - ); } /// @@ -830,8 +805,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu return new AsyncRetryPolicy( policyBuilder, onRetryAsync, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -889,8 +863,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (outcome, timespan, _) => onRetry(outcome, timespan) - ); + (outcome, timespan, _) => onRetry(outcome, timespan)); } /// @@ -912,8 +885,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (outcome, i, timespan, _) => onRetry(outcome, i, timespan) - ); + (outcome, i, timespan, _) => onRetry(outcome, i, timespan)); } /// @@ -935,8 +907,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (outcome, timespan, _) => onRetryAsync(outcome, timespan) - ); + (outcome, timespan, _) => onRetryAsync(outcome, timespan)); } /// @@ -958,8 +929,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P return policyBuilder.WaitAndRetryForeverAsync( (retryCount, _) => sleepDurationProvider(retryCount), - (outcome, i, timespan, _) => onRetryAsync(outcome, i, timespan) - ); + (outcome, i, timespan, _) => onRetryAsync(outcome, i, timespan)); } /// @@ -978,12 +948,11 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryForeverAsync( sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - async (outcome, timespan, ctx) => onRetry(outcome, timespan, ctx) + async (outcome, timespan, ctx) => onRetry(outcome, timespan, ctx)); #pragma warning restore 1998 - ); } /// @@ -1002,12 +971,11 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P { if (onRetry == null) throw new ArgumentNullException(nameof(onRetry)); +#pragma warning disable 1998 // async method has no awaits, will run synchronously return policyBuilder.WaitAndRetryForeverAsync( sleepDurationProvider, -#pragma warning disable 1998 // async method has no awaits, will run synchronously - async (outcome, i, timespan, ctx) => onRetry(outcome, i, timespan, ctx) + async (outcome, i, timespan, ctx) => onRetry(outcome, i, timespan, ctx)); #pragma warning restore 1998 - ); } /// @@ -1025,10 +993,10 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Func, TimeSpan, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForeverAsync( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetryAsync - ); + onRetryAsync); } /// @@ -1046,10 +1014,10 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Func, int, TimeSpan, Context, Task> onRetryAsync) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForeverAsync( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetryAsync - ); + onRetryAsync); } /// @@ -1095,8 +1063,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P return new AsyncRetryPolicy( policyBuilder, (exception, timespan, i, ctx) => onRetryAsync(exception, i, timespan, ctx), - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } } diff --git a/src/Polly/Retry/RetryEngine.cs b/src/Polly/Retry/RetryEngine.cs index 527abe0972..aff987d1a4 100644 --- a/src/Polly/Retry/RetryEngine.cs +++ b/src/Polly/Retry/RetryEngine.cs @@ -10,7 +10,7 @@ internal static TResult Implementation( ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates shouldRetryResultPredicates, Action, TimeSpan, int, Context> onRetry, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, Func, Context, TimeSpan>? sleepDurationProvider = null) { diff --git a/src/Polly/Retry/RetryPolicy.cs b/src/Polly/Retry/RetryPolicy.cs index d94689e1c5..ecf2078c84 100644 --- a/src/Polly/Retry/RetryPolicy.cs +++ b/src/Polly/Retry/RetryPolicy.cs @@ -14,10 +14,9 @@ public class RetryPolicy : Policy, IRetryPolicy internal RetryPolicy( PolicyBuilder policyBuilder, Action onRetry, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, - Func? sleepDurationProvider = null - ) + Func? sleepDurationProvider = null) : base(policyBuilder) { _permittedRetryCount = permittedRetryCount; @@ -39,8 +38,7 @@ protected override TResult Implementation(Func _sleepDurationProvider(retryCount, outcome.Exception, ctx) - : (Func, Context, TimeSpan>?) null - ); + : (Func, Context, TimeSpan>?) null); } /// @@ -56,10 +54,9 @@ public class RetryPolicy : Policy, IRetryPolicy internal RetryPolicy( PolicyBuilder policyBuilder, Action, TimeSpan, int, Context> onRetry, - int permittedRetryCount = Int32.MaxValue, + int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, - Func, Context, TimeSpan>? sleepDurationProvider = null - ) + Func, Context, TimeSpan>? sleepDurationProvider = null) : base(policyBuilder) { _permittedRetryCount = permittedRetryCount; @@ -80,6 +77,5 @@ protected override TResult Implementation(Func onRetry(outcome, ctx) - ); + (outcome, _, _, ctx) => onRetry(outcome, ctx)); } /// @@ -161,8 +160,7 @@ public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder, Action< return new RetryPolicy( policyBuilder, - (outcome, _, i, ctx) => onRetry(outcome, i, ctx) - ); + (outcome, _, i, ctx) => onRetry(outcome, i, ctx)); } /// @@ -205,8 +203,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int re return policyBuilder.WaitAndRetry( retryCount, sleepDurationProvider, - (outcome, span, _, _) => onRetry(outcome, span) - ); + (outcome, span, _, _) => onRetry(outcome, span)); } /// @@ -233,8 +230,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret return policyBuilder.WaitAndRetry( retryCount, sleepDurationProvider, - (outcome, span, _, ctx) => onRetry(outcome, span, ctx) - ); + (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); } /// @@ -267,8 +263,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret policyBuilder, onRetry, retryCount, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -311,8 +306,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret return policyBuilder.WaitAndRetry( retryCount, sleepDurationProvider, - (outcome, span, _, ctx) => onRetry(outcome, span, ctx) - ); + (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); } /// @@ -368,8 +362,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret policyBuilder, onRetry, retryCount, - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } /// @@ -450,8 +443,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumer return new RetryPolicy( policyBuilder, onRetry, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -509,8 +501,7 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, return policyBuilder.WaitAndRetryForever( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, timespan, _) => onRetry(exception, timespan) - ); + (exception, timespan, _) => onRetry(exception, timespan)); } /// @@ -532,8 +523,7 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, return policyBuilder.WaitAndRetryForever( (retryCount, _, _) => sleepDurationProvider(retryCount), - (exception, i, timespan, _) => onRetry(exception, i, timespan) - ); + (exception, i, timespan, _) => onRetry(exception, i, timespan)); } /// @@ -551,10 +541,10 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Action onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForever( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetry - ); + onRetry); } /// @@ -572,10 +562,10 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Action onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForever( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetry - ); + onRetry); } /// @@ -621,7 +611,6 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, return new RetryPolicy( policyBuilder, (exception, timespan, i, ctx) => onRetry(exception, i, timespan, ctx), - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } } diff --git a/src/Polly/Retry/RetryTResultSyntax.cs b/src/Polly/Retry/RetryTResultSyntax.cs index 0d07336c67..e8f3c64826 100644 --- a/src/Polly/Retry/RetryTResultSyntax.cs +++ b/src/Polly/Retry/RetryTResultSyntax.cs @@ -143,8 +143,7 @@ public static RetryPolicy RetryForever(this PolicyBuilder( policyBuilder, - (outcome, _, _, ctx) => onRetry(outcome, ctx) - ); + (outcome, _, _, ctx) => onRetry(outcome, ctx)); } /// @@ -161,8 +160,7 @@ public static RetryPolicy RetryForever(this PolicyBuilder( policyBuilder, - (outcome, _, i, ctx) => onRetry(outcome, i, ctx) - ); + (outcome, _, i, ctx) => onRetry(outcome, i, ctx)); } /// @@ -205,8 +203,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder onRetry(outcome, span) - ); + (outcome, span, _, _) => onRetry(outcome, span)); } /// @@ -233,8 +230,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder onRetry(outcome, span, ctx) - ); + (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); } /// @@ -267,8 +263,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder @@ -311,8 +306,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder onRetry(outcome, span, ctx) - ); + (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); } /// @@ -336,8 +330,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder sleepDurationProvider(i, ctx), - onRetry - ); + onRetry); /// /// Builds a that will wait and retry times. @@ -379,8 +372,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder onRetry(outcome, span, ctx) - ); + (outcome, span, _, ctx) => onRetry(outcome, span, ctx)); } /// @@ -410,8 +402,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder @@ -492,8 +483,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder( policyBuilder, onRetry, - sleepDurationsEnumerable: sleepDurations - ); + sleepDurationsEnumerable: sleepDurations); } /// @@ -551,8 +541,7 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuild return policyBuilder.WaitAndRetryForever( (retryCount, _) => sleepDurationProvider(retryCount), - (exception, timespan, _) => onRetry(exception, timespan) - ); + (exception, timespan, _) => onRetry(exception, timespan)); } /// @@ -574,8 +563,7 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuild return policyBuilder.WaitAndRetryForever( (retryCount, _, _) => sleepDurationProvider(retryCount), - (outcome, i, timespan, _) => onRetry(outcome, i, timespan) - ); + (outcome, i, timespan, _) => onRetry(outcome, i, timespan)); } /// @@ -593,10 +581,10 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuild public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Action, TimeSpan, Context> onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForever( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetry - ); + onRetry); } /// @@ -614,10 +602,10 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuild public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider, Action, int, TimeSpan, Context> onRetry) { if (sleepDurationProvider == null) throw new ArgumentNullException(nameof(sleepDurationProvider)); + return policyBuilder.WaitAndRetryForever( (i, _, ctx) => sleepDurationProvider(i, ctx), - onRetry - ); + onRetry); } /// @@ -663,7 +651,6 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuild return new RetryPolicy( policyBuilder, (exception, timespan, i, ctx) => onRetry(exception, i, timespan, ctx), - sleepDurationProvider: sleepDurationProvider - ); + sleepDurationProvider: sleepDurationProvider); } } diff --git a/src/Polly/Timeout/AsyncTimeoutPolicy.cs b/src/Polly/Timeout/AsyncTimeoutPolicy.cs index 6019d3f7a5..bccd01e82c 100644 --- a/src/Polly/Timeout/AsyncTimeoutPolicy.cs +++ b/src/Polly/Timeout/AsyncTimeoutPolicy.cs @@ -12,8 +12,7 @@ public class AsyncTimeoutPolicy : AsyncPolicy, ITimeoutPolicy internal AsyncTimeoutPolicy( Func timeoutProvider, TimeoutStrategy timeoutStrategy, - Func onTimeoutAsync - ) + Func onTimeoutAsync) { _timeoutProvider = timeoutProvider ?? throw new ArgumentNullException(nameof(timeoutProvider)); _timeoutStrategy = timeoutStrategy; diff --git a/src/Polly/Timeout/AsyncTimeoutSyntax.cs b/src/Polly/Timeout/AsyncTimeoutSyntax.cs index 4114df1fdf..89ec2e51b4 100644 --- a/src/Polly/Timeout/AsyncTimeoutSyntax.cs +++ b/src/Polly/Timeout/AsyncTimeoutSyntax.cs @@ -379,7 +379,6 @@ public static AsyncTimeoutPolicy TimeoutAsync( return new AsyncTimeoutPolicy( timeoutProvider, timeoutStrategy, - onTimeoutAsync - ); + onTimeoutAsync); } } diff --git a/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs b/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs index 640b7028a9..0d5598e60d 100644 --- a/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs +++ b/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs @@ -373,7 +373,6 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func( timeoutProvider, timeoutStrategy, - onTimeoutAsync - ); + onTimeoutAsync); } } diff --git a/src/Polly/Utilities/TimedLock.cs b/src/Polly/Utilities/TimedLock.cs index 9eb0ecd940..6c97b9dce0 100644 --- a/src/Polly/Utilities/TimedLock.cs +++ b/src/Polly/Utilities/TimedLock.cs @@ -78,6 +78,7 @@ private class Sentinel #endif } } + private readonly Sentinel _leakDetector; #endif } diff --git a/src/Polly/Wrap/AsyncPolicyWrap.cs b/src/Polly/Wrap/AsyncPolicyWrap.cs index 0fd31eb6da..7815897b33 100644 --- a/src/Polly/Wrap/AsyncPolicyWrap.cs +++ b/src/Polly/Wrap/AsyncPolicyWrap.cs @@ -38,8 +38,7 @@ protected override Task ImplementationAsync( cancellationToken, continueOnCapturedContext, _outer, - _inner - ); + _inner); /// [DebuggerStepThrough] @@ -51,8 +50,7 @@ protected override Task ImplementationAsync(Func @@ -112,8 +110,7 @@ protected override Task ImplementationAsync(Func ImplementationAsync(Func ImplementationAsync(Func ImplementationAsync(Func @@ -83,8 +82,7 @@ public AsyncPolicyWrap WrapAsync(IAsyncPolicy innerPo return new AsyncPolicyWrap( this, - innerPolicy - ); + innerPolicy); } } @@ -101,8 +99,7 @@ public AsyncPolicyWrap WrapAsync(IAsyncPolicy innerPolicy) return new AsyncPolicyWrap( this, - innerPolicy - ); + innerPolicy); } /// @@ -116,8 +113,7 @@ public AsyncPolicyWrap WrapAsync(IAsyncPolicy innerPolicy) return new AsyncPolicyWrap( this, - innerPolicy - ); + innerPolicy); } } diff --git a/src/Polly/Wrap/PolicyWrap.cs b/src/Polly/Wrap/PolicyWrap.cs index 2591bba5c5..9e47721192 100644 --- a/src/Polly/Wrap/PolicyWrap.cs +++ b/src/Polly/Wrap/PolicyWrap.cs @@ -33,8 +33,7 @@ protected override void Implementation(Action action context, cancellationToken, _outer, - _inner - ); + _inner); /// [DebuggerStepThrough] @@ -44,8 +43,7 @@ protected override TResult Implementation(Func @@ -103,8 +101,7 @@ protected override TResult Implementation(Func @@ -83,8 +82,7 @@ public PolicyWrap Wrap(ISyncPolicy innerPolicy) return new PolicyWrap( this, - innerPolicy - ); + innerPolicy); } } @@ -101,8 +99,7 @@ public PolicyWrap Wrap(ISyncPolicy innerPolicy) return new PolicyWrap( this, - innerPolicy - ); + innerPolicy); } /// @@ -116,8 +113,7 @@ public PolicyWrap Wrap(ISyncPolicy innerPolicy) return new PolicyWrap( this, - innerPolicy - ); + innerPolicy); } }