diff --git a/src/Polly.Benchmarks/Bulkhead.cs b/src/Polly.Benchmarks/Bulkhead.cs index 36a9449c838..8c294dfcc45 100644 --- a/src/Polly.Benchmarks/Bulkhead.cs +++ b/src/Polly.Benchmarks/Bulkhead.cs @@ -17,15 +17,15 @@ public void Bulkhead_Synchronous() } [Benchmark] - public async Task Bulkhead_Asynchronous() + public Task Bulkhead_Asynchronous() { - await AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); } [Benchmark] - public async Task Bulkhead_Asynchronous_With_CancellationToken() + public Task Bulkhead_Asynchronous_With_CancellationToken() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -35,14 +35,14 @@ public int Bulkhead_Synchronous_With_Result() } [Benchmark] - public async Task Bulkhead_Asynchronous_With_Result() + public Task Bulkhead_Asynchronous_With_Result() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); } [Benchmark] - public async Task Bulkhead_Asynchronous_With_Result_With_CancellationToken() + public Task Bulkhead_Asynchronous_With_Result_With_CancellationToken() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } } diff --git a/src/Polly.Benchmarks/Cache.cs b/src/Polly.Benchmarks/Cache.cs index 0161b93a7ad..9254d884171 100644 --- a/src/Polly.Benchmarks/Cache.cs +++ b/src/Polly.Benchmarks/Cache.cs @@ -23,10 +23,10 @@ public class Cache private static readonly Context MissContext = new Context(nameof(MissContext)); [GlobalSetup] - public async Task GlobalSetup() + public Task GlobalSetup() { SyncPolicyHit.Execute((context) => GetObject(), HitContext); - await AsyncPolicyHit.ExecuteAsync((context, token) => GetObjectAsync(token), HitContext, CancellationToken.None); + return AsyncPolicyHit.ExecuteAsync((context, token) => GetObjectAsync(token), HitContext, CancellationToken.None); } [Benchmark] @@ -36,9 +36,9 @@ public object Cache_Synchronous_Hit() } [Benchmark] - public async Task Cache_Asynchronous_Hit() + public Task Cache_Asynchronous_Hit() { - return await AsyncPolicyHit.ExecuteAsync((context, token) => GetObjectAsync(token), HitContext, CancellationToken.None); + return AsyncPolicyHit.ExecuteAsync((context, token) => GetObjectAsync(token), HitContext, CancellationToken.None); } [Benchmark] @@ -48,9 +48,9 @@ public object Cache_Synchronous_Miss() } [Benchmark] - public async Task Cache_Asynchronous_Miss() + public Task Cache_Asynchronous_Miss() { - return await AsyncPolicyMiss.ExecuteAsync((context, token) => GetObjectAsync(token), MissContext, CancellationToken.None); + return AsyncPolicyMiss.ExecuteAsync((context, token) => GetObjectAsync(token), MissContext, CancellationToken.None); } private static object GetObject() => new object(); diff --git a/src/Polly.Benchmarks/CircuitBreaker.cs b/src/Polly.Benchmarks/CircuitBreaker.cs index b07e9c4d344..5d2e5156579 100644 --- a/src/Polly.Benchmarks/CircuitBreaker.cs +++ b/src/Polly.Benchmarks/CircuitBreaker.cs @@ -18,9 +18,9 @@ public void CircuitBreaker_Synchronous_Succeeds() } [Benchmark] - public async Task CircuitBreaker_Asynchronous_Succeeds() + public Task CircuitBreaker_Asynchronous_Succeeds() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -30,8 +30,8 @@ public int CircuitBreaker_Synchronous_With_Result_Succeeds() } [Benchmark] - public async Task CircuitBreaker_Asynchronous_With_Result_Succeeds() + public Task CircuitBreaker_Asynchronous_With_Result_Succeeds() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } } diff --git a/src/Polly.Benchmarks/Fallback.cs b/src/Polly.Benchmarks/Fallback.cs index 7b602777c0e..0745804f1c3 100644 --- a/src/Polly.Benchmarks/Fallback.cs +++ b/src/Polly.Benchmarks/Fallback.cs @@ -17,9 +17,9 @@ public int Fallback_Synchronous_Succeeds() } [Benchmark] - public async Task Fallback_Asynchronous_Succeeds() + public Task Fallback_Asynchronous_Succeeds() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); } [Benchmark] @@ -29,8 +29,8 @@ public int Fallback_Synchronous_Throws() } [Benchmark] - public async Task Fallback_Asynchronous_Throws() + public Task Fallback_Asynchronous_Throws() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncThrowsAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncThrowsAsync()); } } diff --git a/src/Polly.Benchmarks/NoOp.cs b/src/Polly.Benchmarks/NoOp.cs index 4e8666ae9e4..fff1e5579d4 100644 --- a/src/Polly.Benchmarks/NoOp.cs +++ b/src/Polly.Benchmarks/NoOp.cs @@ -17,9 +17,9 @@ public void NoOp_Synchronous() } [Benchmark] - public async Task NoOp_Asynchronous() + public Task NoOp_Asynchronous() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -29,8 +29,8 @@ public int NoOp_Synchronous_With_Result() } [Benchmark] - public async Task NoOp_Asynchronous_With_Result() + public Task NoOp_Asynchronous_With_Result() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } } diff --git a/src/Polly.Benchmarks/PolicyWrap.cs b/src/Polly.Benchmarks/PolicyWrap.cs index 9b8838ea65d..43615d15f75 100644 --- a/src/Polly.Benchmarks/PolicyWrap.cs +++ b/src/Polly.Benchmarks/PolicyWrap.cs @@ -27,9 +27,9 @@ public void PolicyWrap_Synchronous() } [Benchmark] - public async Task PolicyWrap_Asynchronous() + public Task PolicyWrap_Asynchronous() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -39,8 +39,8 @@ public int PolicyWrap_Synchronous_With_Result() } [Benchmark] - public async Task PolicyWrap_Asynchronous_With_Result() + public Task PolicyWrap_Asynchronous_With_Result() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } } diff --git a/src/Polly.Benchmarks/RateLimit.cs b/src/Polly.Benchmarks/RateLimit.cs index c4267856168..85978b8794a 100644 --- a/src/Polly.Benchmarks/RateLimit.cs +++ b/src/Polly.Benchmarks/RateLimit.cs @@ -17,9 +17,9 @@ public void RateLimit_Synchronous_Succeeds() } [Benchmark] - public async Task RateLimit_Asynchronous_Succeeds() + public Task RateLimit_Asynchronous_Succeeds() { - await AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); } [Benchmark] @@ -29,8 +29,8 @@ public int RateLimit_Synchronous_With_Result_Succeeds() } [Benchmark] - public async Task RateLimit_Asynchronous_With_Result_Succeeds() + public Task RateLimit_Asynchronous_With_Result_Succeeds() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); } } diff --git a/src/Polly.Benchmarks/Retry.cs b/src/Polly.Benchmarks/Retry.cs index ad4143c7669..44aa388b467 100644 --- a/src/Polly.Benchmarks/Retry.cs +++ b/src/Polly.Benchmarks/Retry.cs @@ -18,15 +18,15 @@ public void Retry_Synchronous_Succeeds() } [Benchmark] - public async Task Retry_Asynchronous_Succeeds() + public Task Retry_Asynchronous_Succeeds() { - await AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); } [Benchmark] - public async Task Retry_Asynchronous_Succeeds_With_CancellationToken() + public Task Retry_Asynchronous_Succeeds_With_CancellationToken() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -36,15 +36,15 @@ public int Retry_Synchronous_With_Result_Succeeds() } [Benchmark] - public async Task Retry_Asynchronous_With_Result_Succeeds() + public Task Retry_Asynchronous_With_Result_Succeeds() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); } [Benchmark] - public async Task Retry_Asynchronous_With_Result_Succeeds_With_CancellationToken() + public Task Retry_Asynchronous_With_Result_Succeeds_With_CancellationToken() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } [Benchmark] @@ -62,11 +62,11 @@ public void Retry_Synchronous_Throws_Then_Succeeds() } [Benchmark] - public async Task Retry_Asynchronous_Throws_Then_Succeeds() + public Task Retry_Asynchronous_Throws_Then_Succeeds() { int count = 0; - await AsyncPolicy.ExecuteAsync(() => + return AsyncPolicy.ExecuteAsync(() => { if (count++ % 2 == 0) { diff --git a/src/Polly.Benchmarks/Timeout.cs b/src/Polly.Benchmarks/Timeout.cs index 68f84becd9c..d368291d0b4 100644 --- a/src/Polly.Benchmarks/Timeout.cs +++ b/src/Polly.Benchmarks/Timeout.cs @@ -18,15 +18,15 @@ public void Timeout_Synchronous_Succeeds() } [Benchmark] - public async Task Timeout_Asynchronous_Succeeds() + public Task Timeout_Asynchronous_Succeeds() { - await AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.ActionAsync()); } [Benchmark] - public async Task Timeout_Asynchronous_Succeeds_With_CancellationToken() + public Task Timeout_Asynchronous_Succeeds_With_CancellationToken() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionAsync(token), CancellationToken.None); } [Benchmark] @@ -36,20 +36,20 @@ public int Timeout_Synchronous_With_Result_Succeeds() } [Benchmark] - public async Task Timeout_Asynchronous_With_Result_Succeeds() + public Task Timeout_Asynchronous_With_Result_Succeeds() { - return await AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); + return AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync()); } [Benchmark] - public async Task Timeout_Asynchronous_With_Result_Succeeds_With_CancellationToken() + public Task Timeout_Asynchronous_With_Result_Succeeds_With_CancellationToken() { - return await AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.FuncAsync(token), CancellationToken.None); } [Benchmark] - public async Task Timeout_Asynchronous_Times_Out_Optimistic() + public Task Timeout_Asynchronous_Times_Out_Optimistic() { - await AsyncPolicy.ExecuteAsync((token) => Workloads.ActionInfiniteAsync(token), CancellationToken.None); + return AsyncPolicy.ExecuteAsync((token) => Workloads.ActionInfiniteAsync(token), CancellationToken.None); } } diff --git a/src/Polly/Caching/AsyncSerializingCacheProvider.cs b/src/Polly/Caching/AsyncSerializingCacheProvider.cs index e5dfe5e6683..1cd3f34f94b 100644 --- a/src/Polly/Caching/AsyncSerializingCacheProvider.cs +++ b/src/Polly/Caching/AsyncSerializingCacheProvider.cs @@ -51,16 +51,16 @@ public AsyncSerializingCacheProvider(IAsyncCacheProvider wrappedCac /// The cancellation token. /// Whether async calls should continue on a captured synchronization context. /// A which completes when the value has been cached. - public async Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, + public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { - await _wrappedCacheProvider.PutAsync( + return _wrappedCacheProvider.PutAsync( key, _serializer.Serialize(value), ttl, cancellationToken, continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + ); } } @@ -112,15 +112,15 @@ public AsyncSerializingCacheProvider(IAsyncCacheProvider wrappedCac /// The cancellation token. /// Whether async calls should continue on a captured synchronization context. /// A which completes when the value has been cached. - public async Task PutAsync(string key, TResult value, Ttl ttl, CancellationToken cancellationToken, + public Task PutAsync(string key, TResult value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { - await _wrappedCacheProvider.PutAsync( + return _wrappedCacheProvider.PutAsync( key, _serializer.Serialize(value), ttl, cancellationToken, continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + ); } } diff --git a/src/Polly/NoOp/AsyncNoOpPolicy.cs b/src/Polly/NoOp/AsyncNoOpPolicy.cs index ea04eca0e68..21041ffedfb 100644 --- a/src/Polly/NoOp/AsyncNoOpPolicy.cs +++ b/src/Polly/NoOp/AsyncNoOpPolicy.cs @@ -18,7 +18,7 @@ internal AsyncNoOpPolicy() [DebuggerStepThrough] protected override Task ImplementationAsync( Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) - => NoOpEngine.ImplementationAsync(action, context, cancellationToken, continueOnCapturedContext); + => NoOpEngine.ImplementationAsync(action, context, cancellationToken); } /// @@ -34,5 +34,5 @@ internal AsyncNoOpPolicy() [DebuggerStepThrough] protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) - => NoOpEngine.ImplementationAsync(action, context, cancellationToken, continueOnCapturedContext); + => NoOpEngine.ImplementationAsync(action, context, cancellationToken); } diff --git a/src/Polly/NoOp/NoOpEngineAsync.cs b/src/Polly/NoOp/NoOpEngineAsync.cs index 1056d0fe9ea..6da9f2c4810 100644 --- a/src/Polly/NoOp/NoOpEngineAsync.cs +++ b/src/Polly/NoOp/NoOpEngineAsync.cs @@ -6,6 +6,6 @@ namespace Polly.NoOp; internal static partial class NoOpEngine { - internal static async Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) - => await action(context, cancellationToken).ConfigureAwait(continueOnCapturedContext); + internal static Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken) + => action(context, cancellationToken); } diff --git a/src/Polly/Wrap/AsyncPolicyWrapEngine.cs b/src/Polly/Wrap/AsyncPolicyWrapEngine.cs index c5e710ad355..0a196ae0380 100644 --- a/src/Polly/Wrap/AsyncPolicyWrapEngine.cs +++ b/src/Polly/Wrap/AsyncPolicyWrapEngine.cs @@ -6,99 +6,88 @@ namespace Polly.Wrap; internal static class AsyncPolicyWrapEngine { - internal static async Task ImplementationAsync( + internal static Task ImplementationAsync( Func> func, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy innerPolicy) - => await outerPolicy.ExecuteAsync( - async (ctx, ct) => await innerPolicy.ExecuteAsync( + => outerPolicy.ExecuteAsync( + (ctx, ct) => innerPolicy.ExecuteAsync( func, ctx, ct, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), + continueOnCapturedContext), context, cancellationToken, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + continueOnCapturedContext); - internal static async Task ImplementationAsync( + internal static Task ImplementationAsync( Func> func, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy innerPolicy) - => await outerPolicy.ExecuteAsync( - async (ctx, ct) => await innerPolicy.ExecuteAsync( + => outerPolicy.ExecuteAsync( + (ctx, ct) => innerPolicy.ExecuteAsync( func, ctx, ct, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), + continueOnCapturedContext), context, cancellationToken, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + continueOnCapturedContext); - internal static async Task ImplementationAsync( + internal static Task ImplementationAsync( Func> func, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy innerPolicy) - => await outerPolicy.ExecuteAsync( - async (ctx, ct) => await innerPolicy.ExecuteAsync( + => outerPolicy.ExecuteAsync( + (ctx, ct) => innerPolicy.ExecuteAsync( func, ctx, ct, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), + continueOnCapturedContext), context, cancellationToken, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + continueOnCapturedContext); - internal static async Task ImplementationAsync( + internal static Task ImplementationAsync( Func> func, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy innerPolicy) - => await outerPolicy.ExecuteAsync( - async (ctx, ct) => await innerPolicy.ExecuteAsync( + => outerPolicy.ExecuteAsync( + (ctx, ct) => innerPolicy.ExecuteAsync( func, ctx, ct, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), + continueOnCapturedContext), context, cancellationToken, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); + continueOnCapturedContext); - internal static async Task ImplementationAsync( + internal static Task ImplementationAsync( Func action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, IAsyncPolicy innerPolicy) - => await outerPolicy.ExecuteAsync( - async (ctx, ct) => await innerPolicy.ExecuteAsync( + => outerPolicy.ExecuteAsync( + (ctx, ct) => innerPolicy.ExecuteAsync( action, ctx, ct, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), + continueOnCapturedContext), context, cancellationToken, - continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext); - + continueOnCapturedContext); }