diff --git a/src/Polly.Benchmarks/Cache.cs b/src/Polly.Benchmarks/Cache.cs index 3260fe3093a..d6ce9086240 100644 --- a/src/Polly.Benchmarks/Cache.cs +++ b/src/Polly.Benchmarks/Cache.cs @@ -59,7 +59,7 @@ public MemoryCacheProvider(IMemoryCache memoryCache) => return (cacheHit, value); } - public void Put(string key, object value, Ttl ttl) + public void Put(string key, object? value, Ttl ttl) { TimeSpan remaining = DateTimeOffset.MaxValue - DateTimeOffset.UtcNow; var options = new MemoryCacheEntryOptions(); @@ -86,7 +86,7 @@ public void Put(string key, object value, Ttl ttl) public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) => Task.FromResult(TryGet(key)); - public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) + public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { Put(key, value, ttl); return Task.CompletedTask; diff --git a/src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs b/src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs index c36f7dd6c43..8db042c1279 100644 --- a/src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs +++ b/src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs @@ -79,7 +79,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu Policy.BulkheadAsync(maxParallelization, maxQueuingActions); protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) => - action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead); + action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy) bulkhead); #endregion } diff --git a/src/Polly.Specs/Bulkhead/BulkheadScenario.cs b/src/Polly.Specs/Bulkhead/BulkheadScenario.cs index c38cf1496be..e5c4eb1913e 100644 --- a/src/Polly.Specs/Bulkhead/BulkheadScenario.cs +++ b/src/Polly.Specs/Bulkhead/BulkheadScenario.cs @@ -20,5 +20,13 @@ public BulkheadScenario(int maxParallelization, int maxQueuingActions, int total } public object[] ToTheoryData() => - new object[] {_maxParallelization, _maxQueuingActions, _totalTestLoad, _cancelQueuing, _cancelExecuting, _scenario }; + new object[] + { + _maxParallelization, + _maxQueuingActions, + _totalTestLoad, + _cancelQueuing, + _cancelExecuting, + _scenario + }; } diff --git a/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs b/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs index 057d87ce9b0..9c4c3644a9b 100644 --- a/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs +++ b/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs @@ -86,7 +86,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu Policy.BulkheadAsync(maxParallelization, maxQueuingActions); protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) => - action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead); + action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy) bulkhead); #endregion } diff --git a/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs b/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs index 94b225d2083..5e3d18ed4b5 100644 --- a/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs +++ b/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs @@ -9,7 +9,7 @@ public void Single_generic_constructor_should_throw_on_no_wrapped_cache_provider { StubSerializer stubObjectSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); Action configure = () => new AsyncSerializingCacheProvider(null!, stubObjectSerializer); @@ -42,7 +42,7 @@ public async Task Single_generic_SerializingCacheProvider_should_serialize_on_pu bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -66,7 +66,7 @@ public async Task Single_generic_SerializingCacheProvider_should_serialize_on_pu bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object? objectToCache = null; @@ -90,7 +90,7 @@ public async Task Single_generic_SerializingCacheProvider_should_deserialize_on_ bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); @@ -113,7 +113,7 @@ public async Task Single_generic_SerializingCacheProvider_should_not_deserialize bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -134,7 +134,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_ bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -158,7 +158,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_ bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object? objectToCache = null; @@ -182,7 +182,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_ bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -204,7 +204,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_ bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -228,7 +228,7 @@ public void Double_generic_constructor_should_throw_on_no_wrapped_cache_provider { StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); Action configure = () => new AsyncSerializingCacheProvider>(null!, stubTResultSerializer); @@ -261,7 +261,7 @@ public async Task Double_generic_SerializingCacheProvider_should_serialize_on_pu bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -285,7 +285,7 @@ public async Task Double_generic_SerializingCacheProvider_should_serialize_on_pu bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = default; @@ -309,7 +309,7 @@ public async Task Double_generic_SerializingCacheProvider_should_deserialize_on_ bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -318,7 +318,7 @@ public async Task Double_generic_SerializingCacheProvider_should_deserialize_on_ AsyncSerializingCacheProvider> serializingCacheProvider = new AsyncSerializingCacheProvider>(stubCacheProvider.AsyncFor>(), stubTResultSerializer); await stubCacheProvider.PutAsync(key, new StubSerialized(objectToCache), new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false); - (bool cacheHit, object fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); + (bool cacheHit, object? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); cacheHit.Should().BeTrue(); deserializeInvoked.Should().BeTrue(); @@ -331,7 +331,7 @@ public async Task Double_generic_SerializingCacheProvider_should_not_deserialize bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -339,7 +339,7 @@ public async Task Double_generic_SerializingCacheProvider_should_not_deserialize stubCacheProvider.TryGet(key).Item1.Should().BeFalse(); AsyncSerializingCacheProvider> serializingCacheProvider = new AsyncSerializingCacheProvider>(stubCacheProvider.AsyncFor>(), stubTResultSerializer); - (bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); + (bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); cacheHit.Should().BeFalse(); deserializeInvoked.Should().BeFalse(); @@ -352,7 +352,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -376,7 +376,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = default; @@ -401,7 +401,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -411,7 +411,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ stubCacheProvider.AsyncFor>().WithSerializer(stubTResultSerializer); await stubCacheProvider.PutAsync(key, new StubSerialized(objectToCache), new Ttl(TimeSpan.FromMinutes(1)), CancellationToken.None, false); - (bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); + (bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); cacheHit.Should().BeTrue(); deserializeInvoked.Should().BeTrue(); @@ -424,7 +424,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -433,7 +433,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_ AsyncSerializingCacheProvider> serializingCacheProvider = stubCacheProvider.AsyncFor>().WithSerializer(stubTResultSerializer); - (bool cacheHit, ResultPrimitive fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); + (bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false); cacheHit.Should().BeFalse(); deserializeInvoked.Should().BeFalse(); diff --git a/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs b/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs index 43cca91688d..d2f3a70594f 100644 --- a/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs +++ b/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs @@ -9,7 +9,7 @@ public void Single_generic_constructor_should_throw_on_no_wrapped_cache_provider { StubSerializer stubObjectSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); Action configure = () => new SerializingCacheProvider(null!, stubObjectSerializer); @@ -42,7 +42,7 @@ public void Single_generic_SerializingCacheProvider_should_serialize_on_put() bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o);}, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -66,7 +66,7 @@ public void Single_generic_SerializingCacheProvider_should_serialize_on_put_for_ bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object? objectToCache = null; @@ -90,7 +90,7 @@ public void Single_generic_SerializingCacheProvider_should_deserialize_on_get() bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); @@ -113,7 +113,7 @@ public void Single_generic_SerializingCacheProvider_should_not_deserialize_on_ge bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -134,7 +134,7 @@ public void Single_generic_SerializingCacheProvider_from_extension_syntax_should bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -158,7 +158,7 @@ public void Single_generic_SerializingCacheProvider_from_extension_syntax_should bool serializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); object? objectToCache = null; @@ -182,7 +182,7 @@ public void Single_generic_SerializingCacheProvider_from_extension_syntax_should bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); object objectToCache = new object(); @@ -204,7 +204,7 @@ public void Single_generic_SerializingCacheProvider_from_extension_syntax_should bool deserializeInvoked = false; StubSerializer stubSerializer = new StubSerializer( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -228,7 +228,7 @@ public void Double_generic_constructor_should_throw_on_no_wrapped_cache_provider { StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); Action configure = () => new SerializingCacheProvider>(null!, stubTResultSerializer); @@ -261,7 +261,7 @@ public void Double_generic_SerializingCacheProvider_should_serialize_on_put() bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -285,7 +285,7 @@ public void Double_generic_SerializingCacheProvider_should_serialize_on_put_for_ bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = default; @@ -309,7 +309,7 @@ public void Double_generic_SerializingCacheProvider_should_deserialize_on_get() bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -331,7 +331,7 @@ public void Double_generic_SerializingCacheProvider_should_not_deserialize_on_ge bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -350,10 +350,9 @@ public void Double_generic_SerializingCacheProvider_should_not_deserialize_on_ge public void Double_generic_SerializingCacheProvider_from_extension_syntax_should_serialize_on_put() { bool serializeInvoked = false; - StubSerializer> stubTResultSerializer = new StubSerializer>( + var stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original - ); + deserialize: s => s?.Original ?? default); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; string key = "some key"; @@ -377,7 +376,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should bool serializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => { serializeInvoked = true; return new StubSerialized(o); }, - deserialize: s => s.Original + deserialize: s => s?.Original ?? default ); StubCacheProvider stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = default; @@ -403,7 +402,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); ResultPrimitive objectToCache = ResultPrimitive.Good; @@ -413,7 +412,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should stubCacheProvider.For>().WithSerializer(stubTResultSerializer); stubCacheProvider.Put(key, new StubSerialized(objectToCache), new Ttl(TimeSpan.FromMinutes(1))); - (bool cacheHit, ResultPrimitive fromCache) = serializingCacheProvider.TryGet(key); + (bool cacheHit, ResultPrimitive? fromCache) = serializingCacheProvider.TryGet(key); cacheHit.Should().BeTrue(); deserializeInvoked.Should().BeTrue(); @@ -426,7 +425,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should bool deserializeInvoked = false; StubSerializer> stubTResultSerializer = new StubSerializer>( serialize: o => new StubSerialized(o), - deserialize: s => { deserializeInvoked = true; return s.Original; } + deserialize: s => { deserializeInvoked = true; return s?.Original ?? default; } ); var stubCacheProvider = new StubCacheProvider(); string key = "some key"; @@ -435,7 +434,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should SerializingCacheProvider> serializingCacheProvider = stubCacheProvider.For>().WithSerializer(stubTResultSerializer); - (bool cacheHit, ResultPrimitive fromCache) = serializingCacheProvider.TryGet(key); + (bool cacheHit, ResultPrimitive? fromCache) = serializingCacheProvider.TryGet(key); cacheHit.Should().BeFalse(); deserializeInvoked.Should().BeFalse(); diff --git a/src/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs b/src/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs index 33991c509c1..496cd369f9b 100644 --- a/src/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs +++ b/src/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs @@ -46,7 +46,11 @@ public Task ExecuteOnBulkhead(BulkheadPolicy bulkhead) => public Task ExecuteOnBulkhead(BulkheadPolicy bulkhead) => ExecuteThroughSyncBulkheadOuter( - () => bulkhead.Execute(_ => { ExecuteThroughSyncBulkheadInner(); return default; }, CancellationSource.Token) + () => bulkhead.Execute(_ => + { + ExecuteThroughSyncBulkheadInner(); + return default; + }, CancellationSource.Token) ); // Note re TaskCreationOptions.LongRunning: Testing the parallelization of the bulkhead policy efficiently requires the ability to start large numbers of parallel tasks in a short space of time. The ThreadPool's algorithm of only injecting extra threads (when necessary) at a rate of two-per-second however makes high-volume tests using the ThreadPool both slow and flaky. For PCL tests further, ThreadPool.SetMinThreads(...) is not available, to mitigate this. Using TaskCreationOptions.LongRunning allows us to force tasks to be started near-instantly on non-ThreadPool threads. @@ -122,7 +126,11 @@ public Task ExecuteOnBulkheadAsync(AsyncBulkheadPolicy bulkhead) => public Task ExecuteOnBulkheadAsync(AsyncBulkheadPolicy bulkhead) => ExecuteThroughAsyncBulkheadOuter( - () => bulkhead.ExecuteAsync(async _ => { await ExecuteThroughAsyncBulkheadInner(); return default; }, CancellationSource.Token) + () => bulkhead.ExecuteAsync(async _ => + { + await ExecuteThroughAsyncBulkheadInner(); + return default; + }, CancellationSource.Token) ); public Task ExecuteThroughAsyncBulkheadOuter(Func executeThroughBulkheadInner) diff --git a/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs b/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs index d817ba5cdc3..d68092d1ad5 100644 --- a/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs +++ b/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs @@ -7,14 +7,14 @@ internal class StubCacheProvider : ISyncCacheProvider, IAsyncCacheProvider { class CacheItem { - public CacheItem(object value, Ttl ttl) + public CacheItem(object? value, Ttl ttl) { Expiry = DateTimeOffset.MaxValue - SystemClock.DateTimeOffsetUtcNow() > ttl.Timespan ? SystemClock.DateTimeOffsetUtcNow().Add(ttl.Timespan) : DateTimeOffset.MaxValue; Value = value; } public readonly DateTimeOffset Expiry; - public readonly object Value; + public readonly object? Value; } private readonly Dictionary cachedValues = new Dictionary(); @@ -35,7 +35,7 @@ public CacheItem(object value, Ttl ttl) return (false, null); } - public void Put(string key, object value, Ttl ttl) => + public void Put(string key, object? value, Ttl ttl) => cachedValues[key] = new CacheItem(value, ttl); #region Naive async-over-sync implementation @@ -44,7 +44,7 @@ public void Put(string key, object value, Ttl ttl) => public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) => Task.FromResult(TryGet(key)); - public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) + public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { Put(key, value, ttl); return TaskHelper.EmptyTask; diff --git a/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs b/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs index 5f303d97363..bcc041225e4 100644 --- a/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs +++ b/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs @@ -19,7 +19,7 @@ public StubErroringCacheProvider(Exception? getException, Exception? putExceptio return innerProvider.TryGet(key); } - public void Put(string key, object value, Ttl ttl) + public void Put(string key, object? value, Ttl ttl) { if (_putException != null) throw _putException; innerProvider.Put(key, value, ttl); @@ -31,7 +31,7 @@ public void Put(string key, object value, Ttl ttl) public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) => Task.FromResult(TryGet(key)); - public Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) + public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) { Put(key, value, ttl); return TaskHelper.EmptyTask; diff --git a/src/Polly.Specs/Helpers/Caching/StubSerialized.cs b/src/Polly.Specs/Helpers/Caching/StubSerialized.cs index 3b568b04684..9502114b0c1 100644 --- a/src/Polly.Specs/Helpers/Caching/StubSerialized.cs +++ b/src/Polly.Specs/Helpers/Caching/StubSerialized.cs @@ -6,9 +6,9 @@ namespace Polly.Specs.Helpers.Caching; /// The type of the item being 'serialized'. internal class StubSerialized { - public TOriginal Original; + public TOriginal? Original; - public StubSerialized(TOriginal original) => + public StubSerialized(TOriginal? original) => Original = original; } @@ -17,5 +17,5 @@ public StubSerialized(TOriginal original) => /// internal class StubSerialized : StubSerialized { - public StubSerialized(object obj) : base(obj) { } + public StubSerialized(object? obj) : base(obj) { } } diff --git a/src/Polly.Specs/Helpers/Caching/StubSerializer.cs b/src/Polly.Specs/Helpers/Caching/StubSerializer.cs index 55d8f5b199c..b44fad8cf7d 100644 --- a/src/Polly.Specs/Helpers/Caching/StubSerializer.cs +++ b/src/Polly.Specs/Helpers/Caching/StubSerializer.cs @@ -7,17 +7,17 @@ /// The type of the serialized values. internal class StubSerializer : ICacheItemSerializer { - private readonly Func _serialize; - private readonly Func _deserialize; + private readonly Func _serialize; + private readonly Func _deserialize; - public StubSerializer(Func serialize, Func deserialize) + public StubSerializer(Func serialize, Func deserialize) { _serialize = serialize; _deserialize = deserialize; } - public TSerialized Serialize(TResult objectToSerialize) => + public TSerialized? Serialize(TResult? objectToSerialize) => _serialize(objectToSerialize); - public TResult Deserialize(TSerialized objectToDeserialize) => + public TResult? Deserialize(TSerialized? objectToDeserialize) => _deserialize(objectToDeserialize); } diff --git a/src/Polly/Caching/AsyncCacheEngine.cs b/src/Polly/Caching/AsyncCacheEngine.cs index 90fd4d64fa2..1e4657e4c84 100644 --- a/src/Polly/Caching/AsyncCacheEngine.cs +++ b/src/Polly/Caching/AsyncCacheEngine.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; internal static class AsyncCacheEngine { @@ -25,7 +26,7 @@ internal static async Task ImplementationAsync( } bool cacheHit; - TResult valueFromCache; + TResult? valueFromCache; try { (cacheHit, valueFromCache) = await cacheProvider.TryGetAsync(cacheKey, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); @@ -39,7 +40,7 @@ internal static async Task ImplementationAsync( if (cacheHit) { onCacheGet(context, cacheKey); - return valueFromCache; + return valueFromCache!; } else { diff --git a/src/Polly/Caching/AsyncGenericCacheProvider.cs b/src/Polly/Caching/AsyncGenericCacheProvider.cs index 6b6ec5f8a21..f7480745c81 100644 --- a/src/Polly/Caching/AsyncGenericCacheProvider.cs +++ b/src/Polly/Caching/AsyncGenericCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Provides a strongly-typed wrapper over a non-generic CacheProviderAsync. @@ -11,12 +12,12 @@ internal class AsyncGenericCacheProvider : IAsyncCacheProvider _wrappedCacheProvider = nonGenericCacheProvider ?? throw new ArgumentNullException(nameof(nonGenericCacheProvider)); - async Task<(bool, TCacheFormat)> IAsyncCacheProvider.TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) + async Task<(bool, TCacheFormat?)> IAsyncCacheProvider.TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { - (bool cacheHit, object result) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); - return (cacheHit, (TCacheFormat)(result ?? default(TCacheFormat))); + (bool cacheHit, object? result) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); + return (cacheHit, (TCacheFormat?)(result ?? default(TCacheFormat))); } - Task IAsyncCacheProvider.PutAsync(string key, TCacheFormat value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) => + Task IAsyncCacheProvider.PutAsync(string key, TCacheFormat? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) => _wrappedCacheProvider.PutAsync(key, value, ttl, cancellationToken, continueOnCapturedContext); } diff --git a/src/Polly/Caching/AsyncSerializingCacheProvider.cs b/src/Polly/Caching/AsyncSerializingCacheProvider.cs index 7660cdc9bf8..0a12b08864c 100644 --- a/src/Polly/Caching/AsyncSerializingCacheProvider.cs +++ b/src/Polly/Caching/AsyncSerializingCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Defines an which serializes objects of any type in and out of an underlying cache which caches as type . For use with asynchronous . @@ -32,9 +33,9 @@ public AsyncSerializingCacheProvider(IAsyncCacheProvider wrappedCac /// A promising as Result a tuple whose first element is a value indicating whether /// the key was found in the cache, and whose second element is the value from the cache (null if not found). /// - public async Task<(bool, object)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) + public async Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { - (bool cacheHit, TSerialized objectToDeserialize) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); + (bool cacheHit, TSerialized? objectToDeserialize) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); return (cacheHit, cacheHit ? _serializer.Deserialize(objectToDeserialize) : null); } @@ -47,7 +48,7 @@ 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 Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, + public Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) => _wrappedCacheProvider.PutAsync( key, @@ -91,9 +92,9 @@ public AsyncSerializingCacheProvider(IAsyncCacheProvider wrappedCac /// A promising as Result a tuple whose first element is a value indicating whether /// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found). /// - public async Task<(bool, TResult)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) + public async Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { - (bool cacheHit, TSerialized objectToDeserialize) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); + (bool cacheHit, TSerialized? objectToDeserialize) = await _wrappedCacheProvider.TryGetAsync(key, cancellationToken, continueOnCapturedContext).ConfigureAwait(continueOnCapturedContext); return (cacheHit, cacheHit ? _serializer.Deserialize(objectToDeserialize) : default); } @@ -106,7 +107,7 @@ 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 Task PutAsync(string key, TResult value, Ttl ttl, CancellationToken cancellationToken, + public Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext) => _wrappedCacheProvider.PutAsync( key, diff --git a/src/Polly/Caching/CacheEngine.cs b/src/Polly/Caching/CacheEngine.cs index a8806dcb49d..493b5207d4a 100644 --- a/src/Polly/Caching/CacheEngine.cs +++ b/src/Polly/Caching/CacheEngine.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; internal static class CacheEngine { @@ -24,7 +25,7 @@ internal static TResult Implementation( } bool cacheHit; - TResult valueFromCache; + TResult? valueFromCache; try { (cacheHit, valueFromCache) = cacheProvider.TryGet(cacheKey); @@ -38,7 +39,7 @@ internal static TResult Implementation( if (cacheHit) { onCacheGet(context, cacheKey); - return valueFromCache; + return valueFromCache!; } else { diff --git a/src/Polly/Caching/GenericCacheProvider.cs b/src/Polly/Caching/GenericCacheProvider.cs index b5f86703633..b35bdd56406 100644 --- a/src/Polly/Caching/GenericCacheProvider.cs +++ b/src/Polly/Caching/GenericCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Provides a strongly-typed wrapper over a non-generic CacheProvider. @@ -11,12 +12,12 @@ internal class GenericCacheProvider : ISyncCacheProvider _wrappedCacheProvider = nonGenericCacheProvider ?? throw new ArgumentNullException(nameof(nonGenericCacheProvider)); - (bool, TCacheFormat) ISyncCacheProvider.TryGet(string key) + (bool, TCacheFormat?) ISyncCacheProvider.TryGet(string key) { - (bool cacheHit, object result) = _wrappedCacheProvider.TryGet(key); - return (cacheHit, (TCacheFormat) (result ?? default(TCacheFormat))); + (bool cacheHit, object? result) = _wrappedCacheProvider.TryGet(key); + return (cacheHit, (TCacheFormat?) (result ?? default(TCacheFormat))); } - void ISyncCacheProvider.Put(string key, TCacheFormat value, Ttl ttl) => + void ISyncCacheProvider.Put(string key, TCacheFormat? value, Ttl ttl) => _wrappedCacheProvider.Put(key, value, ttl); } diff --git a/src/Polly/Caching/IAsyncCacheProvider.cs b/src/Polly/Caching/IAsyncCacheProvider.cs index fd3de957ee9..3d390a8ea17 100644 --- a/src/Polly/Caching/IAsyncCacheProvider.cs +++ b/src/Polly/Caching/IAsyncCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Defines methods for classes providing asynchronous cache functionality for Polly s. @@ -15,7 +16,7 @@ public interface IAsyncCacheProvider /// A promising as Result a tuple whose first element is a value indicating whether /// the key was found in the cache, and whose second element is the value from the cache (null if not found). /// - Task<(bool, object)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); + Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); /// /// Puts the specified value in the cache asynchronously. @@ -26,7 +27,7 @@ public interface IAsyncCacheProvider /// The cancellation token. /// Whether async calls should continue on a captured synchronization context.Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context. /// A which completes when the value has been cached. - Task PutAsync(string key, object value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); + Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); } /// @@ -44,7 +45,7 @@ public interface IAsyncCacheProvider /// A promising as Result a tuple whose first element is a value indicating whether /// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found). /// - Task<(bool, TResult)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); + Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); /// /// Puts the specified value in the cache asynchronously. @@ -55,5 +56,5 @@ public interface IAsyncCacheProvider /// The cancellation token. /// Whether async calls should continue on a captured synchronization context.Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context. /// A which completes when the value has been cached. - Task PutAsync(string key, TResult value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); + Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); } diff --git a/src/Polly/Caching/ICacheItemSerializer.cs b/src/Polly/Caching/ICacheItemSerializer.cs index 77c337f720f..069f2d96076 100644 --- a/src/Polly/Caching/ICacheItemSerializer.cs +++ b/src/Polly/Caching/ICacheItemSerializer.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Defines operations for serializing and deserializing values being placed in caches by instances. @@ -12,12 +13,12 @@ public interface ICacheItemSerializer /// /// The object to serialize. /// The serialized object - TSerialized Serialize(TResult objectToSerialize); + TSerialized? Serialize(TResult? objectToSerialize); /// /// Deserializes the specified object. /// /// The object to deserialize. /// The deserialized object - TResult Deserialize(TSerialized objectToDeserialize); + TResult? Deserialize(TSerialized? objectToDeserialize); } diff --git a/src/Polly/Caching/ISyncCacheProvider.cs b/src/Polly/Caching/ISyncCacheProvider.cs index 17a6b0b1ba5..6e2eefd6cf3 100644 --- a/src/Polly/Caching/ISyncCacheProvider.cs +++ b/src/Polly/Caching/ISyncCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Defines methods for classes providing synchronous cache functionality for Polly s. @@ -13,7 +14,7 @@ public interface ISyncCacheProvider /// A tuple whose first element is a value indicating whether the key was found in the cache, /// and whose second element is the value from the cache (null if not found). /// - (bool, object) TryGet(string key); + (bool, object?) TryGet(string key); /// /// Puts the specified value in the cache. @@ -21,7 +22,7 @@ public interface ISyncCacheProvider /// The cache key. /// The value to put into the cache. /// The time-to-live for the cache entry. - void Put(string key, object value, Ttl ttl); + void Put(string key, object? value, Ttl ttl); } /// @@ -37,7 +38,7 @@ public interface ISyncCacheProvider /// A tuple whose first element is a value indicating whether the key was found in the cache, /// and whose second element is the value from the cache (default(TResult) if not found). /// - (bool, TResult) TryGet(string key); + (bool, TResult?) TryGet(string key); /// /// Puts the specified value in the cache. @@ -45,5 +46,5 @@ public interface ISyncCacheProvider /// The cache key. /// The value to put into the cache. /// The time-to-live for the cache entry. - void Put(string key, TResult value, Ttl ttl); + void Put(string key, TResult? value, Ttl ttl); } diff --git a/src/Polly/Caching/SerializingCacheProvider.cs b/src/Polly/Caching/SerializingCacheProvider.cs index 551b0175e62..11028319cd8 100644 --- a/src/Polly/Caching/SerializingCacheProvider.cs +++ b/src/Polly/Caching/SerializingCacheProvider.cs @@ -1,4 +1,5 @@ -namespace Polly.Caching; +#nullable enable +namespace Polly.Caching; /// /// Defines an which serializes objects of any type in and out of an underlying cache which caches as type . For use with synchronous . @@ -30,9 +31,9 @@ public SerializingCacheProvider(ISyncCacheProvider wrappedCacheProv /// A tuple whose first element is a value indicating whether the key was found in the cache, /// and whose second element is the value from the cache (null if not found). /// - public (bool, object) TryGet(string key) + public (bool, object?) TryGet(string key) { - (bool cacheHit, TSerialized objectToDeserialize) = _wrappedCacheProvider.TryGet(key); + (bool cacheHit, TSerialized? objectToDeserialize) = _wrappedCacheProvider.TryGet(key); return (cacheHit, cacheHit ? _serializer.Deserialize(objectToDeserialize) : null); } @@ -42,7 +43,7 @@ public SerializingCacheProvider(ISyncCacheProvider wrappedCacheProv /// The cache key. /// The value to put into the cache. /// The time-to-live for the cache entry. - public void Put(string key, object value, Ttl ttl) => + public void Put(string key, object? value, Ttl ttl) => _wrappedCacheProvider.Put(key, _serializer.Serialize(value), ttl); } @@ -77,9 +78,9 @@ public SerializingCacheProvider(ISyncCacheProvider wrappedCacheProv /// A tuple whose first element is a value indicating whether the key was found in the cache, /// and whose second element is the value from the cache (default(TResult) if not found). /// - public (bool, TResult) TryGet(string key) + public (bool, TResult?) TryGet(string key) { - (bool cacheHit, TSerialized objectToDeserialize) = _wrappedCacheProvider.TryGet(key); + (bool cacheHit, TSerialized? objectToDeserialize) = _wrappedCacheProvider.TryGet(key); return (cacheHit, cacheHit ? _serializer.Deserialize(objectToDeserialize) : default); } @@ -89,6 +90,6 @@ public SerializingCacheProvider(ISyncCacheProvider wrappedCacheProv /// The cache key. /// The value to put into the cache. /// The time-to-live for the cache entry. - public void Put(string key, TResult value, Ttl ttl) => + public void Put(string key, TResult? value, Ttl ttl) => _wrappedCacheProvider.Put(key, _serializer.Serialize(value), ttl); } diff --git a/src/Polly/Fallback/AsyncFallbackPolicy.cs b/src/Polly/Fallback/AsyncFallbackPolicy.cs index a3a7c70b324..5e1be370dec 100644 --- a/src/Polly/Fallback/AsyncFallbackPolicy.cs +++ b/src/Polly/Fallback/AsyncFallbackPolicy.cs @@ -23,7 +23,11 @@ protected override Task ImplementationAsync( CancellationToken cancellationToken, bool continueOnCapturedContext) => AsyncFallbackEngine.ImplementationAsync( - async (ctx, ct) => { await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, + async (ctx, ct) => + { + await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); + return EmptyStruct.Instance; + }, context, cancellationToken, ExceptionPredicates, diff --git a/src/Polly/Retry/AsyncRetryPolicy.cs b/src/Polly/Retry/AsyncRetryPolicy.cs index b07690af0b5..721f9f5caa0 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -39,8 +39,8 @@ protected override Task ImplementationAsync(Func _sleepDurationProvider(retryCount, outcome.Exception, ctx) - : (Func, Context, TimeSpan>)null, + ? (retryCount, outcome, ctx) => _sleepDurationProvider(retryCount, outcome.Exception, ctx) + : (Func, Context, TimeSpan>) null, continueOnCapturedContext ); }