diff --git a/src/Polly/Bulkhead/BulkheadSyntax.cs b/src/Polly/Bulkhead/BulkheadSyntax.cs
index afd10398d9d..cdbea4998b1 100644
--- a/src/Polly/Bulkhead/BulkheadSyntax.cs
+++ b/src/Polly/Bulkhead/BulkheadSyntax.cs
@@ -11,10 +11,7 @@ public partial class Policy
/// maxParallelization;Value must be greater than zero.
/// The policy instance.
public static BulkheadPolicy Bulkhead(int maxParallelization)
- {
- Action doNothing = _ => { };
- return Bulkhead(maxParallelization, 0, doNothing);
- }
+ => Bulkhead(maxParallelization, 0, EmptyAction);
///
/// Builds a bulkhead isolation , which limits the maximum concurrency of actions executed through the policy. Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.
@@ -38,10 +35,7 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, Action on
/// maxParallelization;Value must be greater than zero.
/// maxQueuingActions;Value must be greater than or equal to zero.
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions)
- {
- Action doNothing = _ => { };
- return Bulkhead(maxParallelization, maxQueuingActions, doNothing);
- }
+ => Bulkhead(maxParallelization, maxQueuingActions, EmptyAction);
///
/// Builds a bulkhead isolation , which limits the maximum concurrency of actions executed through the policy. Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.
@@ -76,4 +70,9 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
maxQueuingActions,
onBulkheadRejected);
}
+
+ private static void EmptyAction(Context context)
+ {
+ // No-op
+ }
}
diff --git a/src/Polly/Bulkhead/BulkheadTResultSyntax.cs b/src/Polly/Bulkhead/BulkheadTResultSyntax.cs
index c3661c15628..92c0e127919 100644
--- a/src/Polly/Bulkhead/BulkheadTResultSyntax.cs
+++ b/src/Polly/Bulkhead/BulkheadTResultSyntax.cs
@@ -12,10 +12,7 @@ public partial class Policy
/// maxParallelization;Value must be greater than zero.
/// The policy instance.
public static BulkheadPolicy Bulkhead(int maxParallelization)
- {
- Action doNothing = _ => { };
- return Bulkhead(maxParallelization, 0, doNothing);
- }
+ => Bulkhead(maxParallelization, 0, EmptyAction);
///
/// Builds a bulkhead isolation , which limits the maximum concurrency of actions executed through the policy. Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.
@@ -41,10 +38,7 @@ public static BulkheadPolicy Bulkhead(int maxParallelization,
/// maxParallelization;Value must be greater than zero.
/// maxQueuingActions;Value must be greater than or equal to zero.
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions)
- {
- Action doNothing = _ => { };
- return Bulkhead(maxParallelization, maxQueuingActions, doNothing);
- }
+ => Bulkhead(maxParallelization, maxQueuingActions, EmptyAction);
///
/// Builds a bulkhead isolation , which limits the maximum concurrency of actions executed through the policy. Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.
diff --git a/src/Polly/Fallback/AsyncFallbackSyntax.cs b/src/Polly/Fallback/AsyncFallbackSyntax.cs
index 933d6c6db24..b4c5fcb24ff 100644
--- a/src/Polly/Fallback/AsyncFallbackSyntax.cs
+++ b/src/Polly/Fallback/AsyncFallbackSyntax.cs
@@ -14,17 +14,7 @@ public static class AsyncFallbackSyntax
/// Thrown when is .
/// The policy instance.
public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder, Func fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Func doNothing = _ => TaskHelper.EmptyTask;
- return policyBuilder.FallbackAsync(
- fallbackAction,
- doNothing);
- }
+ => policyBuilder.FallbackAsync(fallbackAction, static _ => TaskHelper.EmptyTask);
///
/// Builds an which provides a fallback action if the main execution fails. Executes the main delegate asynchronously, but if this throws a handled exception, first asynchronously calls with details of the handled exception; then asynchronously calls .
@@ -114,12 +104,7 @@ public static class AsyncFallbackTResultSyntax
/// The fallback value to provide.
/// The policy instance.
public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder, TResult fallbackValue)
- {
- Func, Task> doNothing = _ => TaskHelper.EmptyTask;
- return policyBuilder.FallbackAsync(
- _ => Task.FromResult(fallbackValue),
- doNothing);
- }
+ => policyBuilder.FallbackAsync(_ => Task.FromResult(fallbackValue), static _ => TaskHelper.EmptyTask);
///
/// Builds an which provides a fallback value if the main execution fails. Executes the main delegate asynchronously, but if this throws a handled exception or raises a handled result, asynchronously calls and returns its result.
@@ -130,17 +115,7 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui
/// Thrown when is .
/// The policy instance.
public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder, Func> fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Func, Task> doNothing = _ => TaskHelper.EmptyTask;
- return policyBuilder.FallbackAsync(
- fallbackAction,
- doNothing);
- }
+ => policyBuilder.FallbackAsync(fallbackAction, static _ => TaskHelper.EmptyTask);
///
/// Builds an which provides a fallback value if the main execution fails. Executes the main delegate asynchronously, but if this throws a handled exception or raises a handled result, first asynchronously calls with details of the handled exception or result; then returns .
@@ -259,8 +234,8 @@ public static AsyncFallbackPolicy FallbackAsync(this PolicyBui
}
return new AsyncFallbackPolicy(
- policyBuilder,
- onFallbackAsync,
- fallbackAction);
+ policyBuilder,
+ onFallbackAsync,
+ fallbackAction);
}
}
diff --git a/src/Polly/Fallback/FallbackSyntax.cs b/src/Polly/Fallback/FallbackSyntax.cs
index 0fa17a1f430..616f291930b 100644
--- a/src/Polly/Fallback/FallbackSyntax.cs
+++ b/src/Polly/Fallback/FallbackSyntax.cs
@@ -14,15 +14,7 @@ public static class FallbackSyntax
/// Thrown when is .
/// The policy instance.
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Action doNothing = _ => { };
- return policyBuilder.Fallback(fallbackAction, doNothing);
- }
+ => policyBuilder.Fallback(fallbackAction, EmptyAction);
///
/// Builds a which provides a fallback action if the main execution fails. Executes the main delegate, but if this throws a handled exception, calls .
@@ -32,15 +24,7 @@ public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action f
/// Thrown when is .
/// The policy instance.
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Action doNothing = _ => { };
- return policyBuilder.Fallback(fallbackAction, doNothing);
- }
+ => policyBuilder.Fallback(fallbackAction, EmptyAction);
///
/// Builds a which provides a fallback action if the main execution fails. Executes the main delegate, but if this throws a handled exception, first calls with details of the handled exception; then calls .
@@ -164,6 +148,11 @@ public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action
@@ -179,10 +168,7 @@ public static class FallbackTResultSyntax
/// The fallback value to provide.
/// The policy instance.
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, TResult fallbackValue)
- {
- Action> doNothing = _ => { };
- return policyBuilder.Fallback(() => fallbackValue, doNothing);
- }
+ => policyBuilder.Fallback(() => fallbackValue, EmptyAction);
///
/// Builds a which provides a fallback value if the main execution fails. Executes the main delegate, but if this throws a handled exception or raises a handled result, calls and returns its result.
@@ -193,15 +179,7 @@ public static FallbackPolicy Fallback(this PolicyBuilderThrown when is .
/// The policy instance.
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Func fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Action> doNothing = _ => { };
- return policyBuilder.Fallback(fallbackAction, doNothing);
- }
+ => policyBuilder.Fallback(fallbackAction, EmptyAction);
///
/// Builds a which provides a fallback value if the main execution fails. Executes the main delegate, but if this throws a handled exception or raises a handled result, calls and returns its result.
@@ -212,15 +190,7 @@ public static FallbackPolicy Fallback(this PolicyBuilderThrown when is .
/// The policy instance.
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Func fallbackAction)
- {
- if (fallbackAction == null)
- {
- throw new ArgumentNullException(nameof(fallbackAction));
- }
-
- Action> doNothing = _ => { };
- return policyBuilder.Fallback(fallbackAction, doNothing);
- }
+ => policyBuilder.Fallback(fallbackAction, EmptyAction);
///
/// Builds a which provides a fallback value if the main execution fails. Executes the main delegate, but if this throws a handled exception or raises a handled result, first calls with details of the handled exception or result; then returns .
@@ -387,4 +357,9 @@ public static FallbackPolicy Fallback(this PolicyBuilder(DelegateResult result)
+ {
+ // No-op
+ }
}
diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj
index 4078c2f8734..2d17bf02a62 100644
--- a/src/Polly/Polly.csproj
+++ b/src/Polly/Polly.csproj
@@ -5,7 +5,7 @@
Polly
true
Library
- 97
+ 100
true
$(NoWarn);RS0037
diff --git a/src/Polly/Retry/AsyncRetryTResultSyntax.cs b/src/Polly/Retry/AsyncRetryTResultSyntax.cs
index a55aabe0186..668a8812601 100644
--- a/src/Polly/Retry/AsyncRetryTResultSyntax.cs
+++ b/src/Polly/Retry/AsyncRetryTResultSyntax.cs
@@ -22,11 +22,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilderThe retry count.
/// The policy instance.
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount)
- {
- Action, int> doNothing = (_, _) => { };
-
- return policyBuilder.RetryAsync(retryCount, doNothing);
- }
+ => policyBuilder.RetryAsync(retryCount, static (_, _) => { });
///
/// Builds an that will retry once
@@ -183,11 +179,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilderThe policy builder.
/// The policy instance.
public static AsyncRetryPolicy RetryForeverAsync(this PolicyBuilder policyBuilder)
- {
- Action> doNothing = _ => { };
-
- return policyBuilder.RetryForeverAsync(doNothing);
- }
+ => policyBuilder.RetryForeverAsync(static _ => { });
///
/// Builds an that will retry indefinitely
@@ -368,11 +360,7 @@ public static AsyncRetryPolicy RetryForeverAsync(this PolicyBu
/// The function that provides the duration to wait for a particular retry attempt.
/// The policy instance.
public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func sleepDurationProvider)
- {
- Action, TimeSpan> doNothing = (_, _) => { };
-
- return policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetryAsync(retryCount, sleepDurationProvider, EmptyAction);
///
/// Builds an that will wait and retry times
@@ -388,8 +376,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu
/// The policy instance.
/// retryCount;Value must be greater than or equal to zero.
/// Thrown when or is .
- public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount,
- Func sleepDurationProvider, Action, TimeSpan> onRetry)
+ public static AsyncRetryPolicy WaitAndRetryAsync(
+ this PolicyBuilder policyBuilder,
+ int retryCount,
+ Func sleepDurationProvider,
+ Action, TimeSpan> onRetry)
{
if (onRetry == null)
{
@@ -667,8 +658,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu
/// The policy instance.
/// retryCount;Value must be greater than or equal to zero.
/// Thrown when or is .
- public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount,
- Func sleepDurationProvider, Func, TimeSpan, int, Context, Task> onRetryAsync)
+ public static AsyncRetryPolicy WaitAndRetryAsync(
+ this PolicyBuilder policyBuilder,
+ int retryCount,
+ Func sleepDurationProvider,
+ Func, TimeSpan, int, Context, Task> onRetryAsync)
{
if (sleepDurationProvider == null)
{
@@ -695,8 +689,11 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu
/// The policy instance.
/// retryCount;Value must be greater than or equal to zero.
/// Thrown when or is .
- public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount,
- Func, Context, TimeSpan> sleepDurationProvider, Func, TimeSpan, int, Context, Task> onRetryAsync)
+ public static AsyncRetryPolicy WaitAndRetryAsync(
+ this PolicyBuilder policyBuilder,
+ int retryCount,
+ Func, Context, TimeSpan> sleepDurationProvider,
+ Func, TimeSpan, int, Context, Task> onRetryAsync)
{
if (retryCount < 0)
{
@@ -730,11 +727,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu
/// The sleep durations to wait for on each retry.
/// The policy instance.
public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, IEnumerable sleepDurations)
- {
- Action, TimeSpan> doNothing = (_, _) => { };
-
- return policyBuilder.WaitAndRetryAsync(sleepDurations, doNothing);
- }
+ => policyBuilder.WaitAndRetryAsync(sleepDurations, EmptyAction);
///
/// Builds an that will wait and retry as many times as there are provided
@@ -903,16 +896,7 @@ public static AsyncRetryPolicy WaitAndRetryAsync(this PolicyBu
/// The policy instance.
/// Thrown when is .
public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func sleepDurationProvider)
- {
- if (sleepDurationProvider == null)
- {
- throw new ArgumentNullException(nameof(sleepDurationProvider));
- }
-
- Action, TimeSpan> doNothing = (_, _) => { };
-
- return policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, EmptyAction);
///
/// Builds an that will wait and retry indefinitely until the action succeeds.
@@ -925,16 +909,7 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P
/// The policy instance.
/// Thrown when is .
public static AsyncRetryPolicy WaitAndRetryForeverAsync(this PolicyBuilder policyBuilder, Func sleepDurationProvider)
- {
- if (sleepDurationProvider == null)
- {
- throw new ArgumentNullException(nameof(sleepDurationProvider));
- }
-
- Action, TimeSpan, Context> doNothing = (_, _, _) => { };
-
- return policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetryForeverAsync(sleepDurationProvider, static (_, _, _) => { });
///
/// Builds an that will wait and retry indefinitely until the action succeeds,
@@ -1221,5 +1196,10 @@ public static AsyncRetryPolicy WaitAndRetryForeverAsync(this P
(exception, timespan, i, ctx) => onRetryAsync(exception, i, timespan, ctx),
sleepDurationProvider: sleepDurationProvider);
}
+
+ private static void EmptyAction(DelegateResult result, TimeSpan retryAfter)
+ {
+ // No-op
+ }
}
diff --git a/src/Polly/Retry/RetrySyntax.cs b/src/Polly/Retry/RetrySyntax.cs
index fb13862da0b..f21133b1d5f 100644
--- a/src/Polly/Retry/RetrySyntax.cs
+++ b/src/Polly/Retry/RetrySyntax.cs
@@ -20,11 +20,7 @@ public static RetryPolicy Retry(this PolicyBuilder policyBuilder) =>
/// The retry count.
/// The policy instance.
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount)
- {
- Action doNothing = (_, _) => { };
-
- return policyBuilder.Retry(retryCount, doNothing);
- }
+ => policyBuilder.Retry(retryCount, static (_, _) => { });
///
/// Builds a that will retry once
@@ -107,11 +103,7 @@ public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount
/// The policy builder.
/// The policy instance.
public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder)
- {
- Action doNothing = _ => { };
-
- return policyBuilder.RetryForever(doNothing);
- }
+ => policyBuilder.RetryForever(static _ => { });
///
/// Builds a that will retry indefinitely
@@ -199,11 +191,7 @@ public static RetryPolicy RetryForever(this PolicyBuilder policyBuilder, Action<
/// The function that provides the duration to wait for a particular retry attempt.
/// The policy instance.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func sleepDurationProvider)
- {
- Action doNothing = (_, _, _, _) => { };
-
- return policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, EmptyHandlerWithContext);
///
/// Builds a that will wait and retry times
@@ -307,11 +295,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret
/// The function that provides the duration to wait for a particular retry attempt.
/// The policy instance.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func sleepDurationProvider)
- {
- Action doNothing = (_, _, _, _) => { };
-
- return policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, EmptyHandlerWithContext);
///
/// Builds a that will wait and retry times
@@ -410,11 +394,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int ret
/// The sleep durations to wait for on each retry.
/// The policy instance.
public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable sleepDurations)
- {
- Action doNothing = (_, _) => { };
-
- return policyBuilder.WaitAndRetry(sleepDurations, doNothing);
- }
+ => policyBuilder.WaitAndRetry(sleepDurations, EmptyHandler);
///
/// Builds a that will wait and retry as many times as there are provided
@@ -494,16 +474,7 @@ public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumer
/// The policy instance.
/// Thrown when is .
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider)
- {
- if (sleepDurationProvider == null)
- {
- throw new ArgumentNullException(nameof(sleepDurationProvider));
- }
-
- Action doNothing = (_, _) => { };
-
- return policyBuilder.WaitAndRetryForever(sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetryForever(sleepDurationProvider, EmptyHandler);
///
/// Builds a that will wait and retry indefinitely until the action succeeds.
@@ -515,16 +486,7 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder,
/// The policy instance.
/// Thrown when is .
public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func sleepDurationProvider)
- {
- if (sleepDurationProvider == null)
- {
- throw new ArgumentNullException(nameof(sleepDurationProvider));
- }
-
- Action doNothing = (_, _, _) => { };
-
- return policyBuilder.WaitAndRetryForever(sleepDurationProvider, doNothing);
- }
+ => policyBuilder.WaitAndRetryForever(sleepDurationProvider, static (_, _, _) => { });
///
/// Builds a that will wait and retry indefinitely until the action succeeds,
@@ -691,4 +653,14 @@ public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder,
(exception, timespan, i, ctx) => onRetry(exception, i, timespan, ctx),
sleepDurationProvider: sleepDurationProvider);
}
+
+ private static void EmptyHandler(Exception exception, TimeSpan retryAfter)
+ {
+ // No-op
+ }
+
+ private static void EmptyHandlerWithContext(Exception exception, TimeSpan retryAfter, int attempts, Context context)
+ {
+ // No-op
+ }
}
diff --git a/src/Polly/Timeout/TimeoutTResultSyntax.cs b/src/Polly/Timeout/TimeoutTResultSyntax.cs
index 878feb8f36c..1856c38270e 100644
--- a/src/Polly/Timeout/TimeoutTResultSyntax.cs
+++ b/src/Polly/Timeout/TimeoutTResultSyntax.cs
@@ -12,9 +12,7 @@ public partial class Policy
public static TimeoutPolicy Timeout(int seconds)
{
TimeoutValidator.ValidateSecondsTimeout(seconds);
- Action doNothing = (_, _, _, _) => { };
-
- return Timeout(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, doNothing);
+ return Timeout(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, EmptyHandler);
}
///
@@ -28,9 +26,7 @@ public static TimeoutPolicy Timeout(int seconds)
public static TimeoutPolicy Timeout(int seconds, TimeoutStrategy timeoutStrategy)
{
TimeoutValidator.ValidateSecondsTimeout(seconds);
- Action doNothing = (_, _, _, _) => { };
-
- return Timeout(_ => TimeSpan.FromSeconds(seconds), timeoutStrategy, doNothing);
+ return Timeout(_ => TimeSpan.FromSeconds(seconds), timeoutStrategy, EmptyHandler);
}
///
@@ -120,9 +116,7 @@ public static TimeoutPolicy Timeout(TimeSpan timeout)
#pragma warning restore S3872
{
TimeoutValidator.ValidateTimeSpanTimeout(timeout);
- Action doNothing = (_, _, _, _) => { };
-
- return Timeout(_ => timeout, TimeoutStrategy.Optimistic, doNothing);
+ return Timeout(_ => timeout, TimeoutStrategy.Optimistic, EmptyHandler);
}
#pragma warning disable S3872
@@ -138,9 +132,7 @@ public static TimeoutPolicy Timeout(TimeSpan timeout, TimeoutS
#pragma warning restore S3872
{
TimeoutValidator.ValidateTimeSpanTimeout(timeout);
- Action doNothing = (_, _, _, _) => { };
-
- return Timeout(_ => timeout, timeoutStrategy, doNothing);
+ return Timeout(_ => timeout, timeoutStrategy, EmptyHandler);
}
#pragma warning disable S3872
@@ -231,8 +223,7 @@ public static TimeoutPolicy Timeout(Func timeoutProv
throw new ArgumentNullException(nameof(timeoutProvider));
}
- Action doNothing = (_, _, _, _) => { };
- return Timeout(_ => timeoutProvider(), TimeoutStrategy.Optimistic, doNothing);
+ return Timeout(_ => timeoutProvider(), TimeoutStrategy.Optimistic, EmptyHandler);
}
///
@@ -250,8 +241,7 @@ public static TimeoutPolicy Timeout(Func timeoutProv
throw new ArgumentNullException(nameof(timeoutProvider));
}
- Action doNothing = (_, _, _, _) => { };
- return Timeout(_ => timeoutProvider(), timeoutStrategy, doNothing);
+ return Timeout(_ => timeoutProvider(), timeoutStrategy, EmptyHandler);
}
///
@@ -344,10 +334,7 @@ public static TimeoutPolicy Timeout(Func timeoutProv
/// Thrown when is .
/// The policy instance.
public static TimeoutPolicy Timeout(Func timeoutProvider)
- {
- Action doNothing = (_, _, _, _) => { };
- return Timeout(timeoutProvider, TimeoutStrategy.Optimistic, doNothing);
- }
+ => Timeout(timeoutProvider, TimeoutStrategy.Optimistic, EmptyHandler);
///
/// Builds a that will wait for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout.
@@ -358,10 +345,7 @@ public static TimeoutPolicy Timeout(Func ti
/// The policy instance.
/// Thrown when is .
public static TimeoutPolicy Timeout(Func timeoutProvider, TimeoutStrategy timeoutStrategy)
- {
- Action doNothing = (_, _, _, _) => { };
- return Timeout(timeoutProvider, timeoutStrategy, doNothing);
- }
+ => Timeout(timeoutProvider, timeoutStrategy, EmptyHandler);
///
/// Builds a that will wait for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout.
diff --git a/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs b/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs
index 3fad46ce4d2..c87bf4e068e 100644
--- a/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs
+++ b/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs
@@ -17,31 +17,28 @@ public void Should_throw_when_fallback_func_is_null()
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
- [Fact]
- public void Should_throw_when_fallback_func_is_null_with_onFallback()
- {
- Func fallbackActionAsync = null!;
- Func onFallbackAsync = _ => TaskHelper.EmptyTask;
+ policy = () => Policy
+ .Handle()
+ .FallbackAsync(fallbackActionAsync, _ => TaskHelper.EmptyTask);
- Action policy = () => Policy
+ Should.Throw(policy)
+ .ParamName.ShouldBe("fallbackAction");
+
+ Func fallbackActionAsyncContext = null!;
+
+ policy = () => Policy
.Handle()
- .FallbackAsync(fallbackActionAsync, onFallbackAsync);
+ .FallbackAsync(fallbackActionAsyncContext, (_, _) => TaskHelper.EmptyTask);
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
- [Fact]
- public void Should_throw_when_fallback_func_is_null_with_onFallback_with_context()
- {
- Func fallbackActionAsync = null!;
- Func onFallbackAsync = (_, _) => TaskHelper.EmptyTask;
+ Func fallbackActionAsyncExceptionContext = null!;
- Action policy = () => Policy
- .Handle()
- .FallbackAsync(fallbackActionAsync, onFallbackAsync);
+ policy = () => Policy
+ .Handle()
+ .FallbackAsync(fallbackActionAsyncExceptionContext, (_, _) => TaskHelper.EmptyTask);
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
@@ -50,33 +47,27 @@ public void Should_throw_when_fallback_func_is_null_with_onFallback_with_context
[Fact]
public void Should_throw_when_onFallback_delegate_is_null()
{
- Func fallbackActionAsync = _ => TaskHelper.EmptyTask;
Func onFallbackAsync = null!;
Action policy = () => Policy
- .Handle()
- .FallbackAsync(fallbackActionAsync, onFallbackAsync);
+ .Handle()
+ .FallbackAsync(_ => TaskHelper.EmptyTask, onFallbackAsync);
Should.Throw(policy)
.ParamName.ShouldBe("onFallbackAsync");
+ Func onFallbackAsyncContext = null!;
+
policy = () => Policy
.Handle()
- .FallbackAsync(fallbackActionAsync, onFallbackAsync);
+ .FallbackAsync((_, _) => TaskHelper.EmptyTask, onFallbackAsyncContext);
Should.Throw(policy)
.ParamName.ShouldBe("onFallbackAsync");
- }
- [Fact]
- public void Should_throw_when_onFallback_delegate_is_null_with_context()
- {
- Func fallbackActionAsync = (_, _) => TaskHelper.EmptyTask;
- Func onFallbackAsync = null!;
-
- Action policy = () => Policy
- .Handle()
- .FallbackAsync(fallbackActionAsync, onFallbackAsync);
+ policy = () => Policy
+ .Handle()
+ .FallbackAsync((_, _, _) => TaskHelper.EmptyTask, onFallbackAsyncContext);
Should.Throw(policy)
.ParamName.ShouldBe("onFallbackAsync");
diff --git a/test/Polly.Specs/Fallback/FallbackSpecs.cs b/test/Polly.Specs/Fallback/FallbackSpecs.cs
index 614d02b9f05..f573d058b0b 100644
--- a/test/Polly.Specs/Fallback/FallbackSpecs.cs
+++ b/test/Polly.Specs/Fallback/FallbackSpecs.cs
@@ -42,72 +42,44 @@ public void Should_throw_when_fallback_action_is_null()
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
-
- [Fact]
- public void Should_throw_when_fallback_action_with_cancellation_is_null()
- {
- Action fallbackAction = null!;
- Action policy = () => Policy
+ policy = () => Policy
.Handle()
- .Fallback(fallbackAction);
+ .Fallback(fallbackAction, _ => { });
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
- [Fact]
- public void Should_throw_when_fallback_action_is_null_with_onFallback()
- {
- Action fallbackAction = null!;
- Action onFallback = _ => { };
-
- Action policy = () => Policy
+ policy = () => Policy
.Handle()
- .Fallback(fallbackAction, onFallback);
+ .Fallback(fallbackActionToken, _ => { });
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
- [Fact]
- public void Should_throw_when_fallback_action_with_cancellation_is_null_with_onFallback()
- {
- Action fallbackAction = null!;
- Action onFallback = _ => { };
+ Action fallbackActionContext = null!;
- Action policy = () => Policy
+ policy = () => Policy
.Handle()
- .Fallback(fallbackAction, onFallback);
+ .Fallback(fallbackActionContext, (_, _) => { });
Should.Throw(policy)
.ParamName.ShouldBe("fallbackAction");
- }
- [Fact]
- public void Should_throw_when_fallback_action_is_null_with_onFallback_with_context()
- {
- Action fallbackAction = null!;
- Action onFallback = (_, _) => { };
+ Action