Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/Polly/Bulkhead/BulkheadSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ public partial class Policy
/// <exception cref="ArgumentOutOfRangeException">maxParallelization;Value must be greater than zero.</exception>
/// <returns>The policy instance.</returns>
public static BulkheadPolicy Bulkhead(int maxParallelization)
{
Action<Context> doNothing = _ => { };
return Bulkhead(maxParallelization, 0, doNothing);
}
=> Bulkhead(maxParallelization, 0, EmptyAction);

/// <summary>
/// <para>Builds a bulkhead isolation <see cref="Policy"/>, 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.</para>
Expand All @@ -38,10 +35,7 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, Action<Context> on
/// <exception cref="ArgumentOutOfRangeException">maxParallelization;Value must be greater than zero.</exception>
/// <exception cref="ArgumentOutOfRangeException">maxQueuingActions;Value must be greater than or equal to zero.</exception>
public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions)
{
Action<Context> doNothing = _ => { };
return Bulkhead(maxParallelization, maxQueuingActions, doNothing);
}
=> Bulkhead(maxParallelization, maxQueuingActions, EmptyAction);

/// <summary>
/// Builds a bulkhead isolation <see cref="Policy" />, 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.
Expand Down Expand Up @@ -76,4 +70,9 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi
maxQueuingActions,
onBulkheadRejected);
}

private static void EmptyAction(Context context)
{
// No-op
}
}
10 changes: 2 additions & 8 deletions src/Polly/Bulkhead/BulkheadTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public partial class Policy
/// <exception cref="ArgumentOutOfRangeException">maxParallelization;Value must be greater than zero.</exception>
/// <returns>The policy instance.</returns>
public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization)
{
Action<Context> doNothing = _ => { };
return Bulkhead<TResult>(maxParallelization, 0, doNothing);
}
=> Bulkhead<TResult>(maxParallelization, 0, EmptyAction);

/// <summary>
/// <para>Builds a bulkhead isolation <see cref="Policy{TResult}"/>, 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.</para>
Expand All @@ -41,10 +38,7 @@ public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization,
/// <exception cref="ArgumentOutOfRangeException">maxParallelization;Value must be greater than zero.</exception>
/// <exception cref="ArgumentOutOfRangeException">maxQueuingActions;Value must be greater than or equal to zero.</exception>
public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization, int maxQueuingActions)
{
Action<Context> doNothing = _ => { };
return Bulkhead<TResult>(maxParallelization, maxQueuingActions, doNothing);
}
=> Bulkhead<TResult>(maxParallelization, maxQueuingActions, EmptyAction);

/// <summary>
/// Builds a bulkhead isolation <see cref="Policy{TResult}" />, 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.
Expand Down
37 changes: 6 additions & 31 deletions src/Polly/Fallback/AsyncFallbackSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ public static class AsyncFallbackSyntax
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static AsyncFallbackPolicy FallbackAsync(this PolicyBuilder policyBuilder, Func<CancellationToken, Task> fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Func<Exception, Task> doNothing = _ => TaskHelper.EmptyTask;
return policyBuilder.FallbackAsync(
fallbackAction,
doNothing);
}
=> policyBuilder.FallbackAsync(fallbackAction, static _ => TaskHelper.EmptyTask);

/// <summary>
/// Builds an <see cref="AsyncFallbackPolicy"/> 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 <paramref name="onFallbackAsync"/> with details of the handled exception; then asynchronously calls <paramref name="fallbackAction"/>.
Expand Down Expand Up @@ -114,12 +104,7 @@ public static class AsyncFallbackTResultSyntax
/// <param name="fallbackValue">The fallback <typeparamref name="TResult"/> value to provide.</param>
/// <returns>The policy instance.</returns>
public static AsyncFallbackPolicy<TResult> FallbackAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, TResult fallbackValue)
{
Func<DelegateResult<TResult>, Task> doNothing = _ => TaskHelper.EmptyTask;
return policyBuilder.FallbackAsync(
_ => Task.FromResult(fallbackValue),
doNothing);
}
=> policyBuilder.FallbackAsync(_ => Task.FromResult(fallbackValue), static _ => TaskHelper.EmptyTask);

/// <summary>
/// Builds an <see cref="AsyncFallbackPolicy{TResult}"/> 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 <paramref name="fallbackAction"/> and returns its result.
Expand All @@ -130,17 +115,7 @@ public static AsyncFallbackPolicy<TResult> FallbackAsync<TResult>(this PolicyBui
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static AsyncFallbackPolicy<TResult> FallbackAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<CancellationToken, Task<TResult>> fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Func<DelegateResult<TResult>, Task> doNothing = _ => TaskHelper.EmptyTask;
return policyBuilder.FallbackAsync(
fallbackAction,
doNothing);
}
=> policyBuilder.FallbackAsync(fallbackAction, static _ => TaskHelper.EmptyTask);

/// <summary>
/// Builds an <see cref="AsyncFallbackPolicy{TResult}"/> 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 <paramref name="onFallbackAsync"/> with details of the handled exception or result; then returns <paramref name="fallbackValue"/>.
Expand Down Expand Up @@ -259,8 +234,8 @@ public static AsyncFallbackPolicy<TResult> FallbackAsync<TResult>(this PolicyBui
}

return new AsyncFallbackPolicy<TResult>(
policyBuilder,
onFallbackAsync,
fallbackAction);
policyBuilder,
onFallbackAsync,
fallbackAction);
}
}
55 changes: 15 additions & 40 deletions src/Polly/Fallback/FallbackSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ public static class FallbackSyntax
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Action<Exception> doNothing = _ => { };
return policyBuilder.Fallback(fallbackAction, doNothing);
}
=> policyBuilder.Fallback(fallbackAction, EmptyAction);

/// <summary>
/// Builds a <see cref="FallbackPolicy"/> which provides a fallback action if the main execution fails. Executes the main delegate, but if this throws a handled exception, calls <paramref name="fallbackAction"/>.
Expand All @@ -32,15 +24,7 @@ public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action f
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action<CancellationToken> fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Action<Exception> doNothing = _ => { };
return policyBuilder.Fallback(fallbackAction, doNothing);
}
=> policyBuilder.Fallback(fallbackAction, EmptyAction);

/// <summary>
/// Builds a <see cref="FallbackPolicy"/> which provides a fallback action if the main execution fails. Executes the main delegate, but if this throws a handled exception, first calls <paramref name="onFallback"/> with details of the handled exception; then calls <paramref name="fallbackAction"/>.
Expand Down Expand Up @@ -164,6 +148,11 @@ public static FallbackPolicy Fallback(this PolicyBuilder policyBuilder, Action<E
onFallback,
fallbackAction);
}

private static void EmptyAction(Exception exception)
{
// No-op
}
}

/// <summary>
Expand All @@ -179,10 +168,7 @@ public static class FallbackTResultSyntax
/// <param name="fallbackValue">The fallback <typeparamref name="TResult"/> value to provide.</param>
/// <returns>The policy instance.</returns>
public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResult> policyBuilder, TResult fallbackValue)
{
Action<DelegateResult<TResult>> doNothing = _ => { };
return policyBuilder.Fallback(() => fallbackValue, doNothing);
}
=> policyBuilder.Fallback(() => fallbackValue, EmptyAction);

/// <summary>
/// Builds a <see cref="FallbackPolicy"/> 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 <paramref name="fallbackAction"/> and returns its result.
Expand All @@ -193,15 +179,7 @@ public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResu
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<TResult> fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Action<DelegateResult<TResult>> doNothing = _ => { };
return policyBuilder.Fallback(fallbackAction, doNothing);
}
=> policyBuilder.Fallback(fallbackAction, EmptyAction);

/// <summary>
/// Builds a <see cref="FallbackPolicy"/> 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 <paramref name="fallbackAction"/> and returns its result.
Expand All @@ -212,15 +190,7 @@ public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResu
/// <exception cref="ArgumentNullException">Thrown when <paramref name="fallbackAction"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<CancellationToken, TResult> fallbackAction)
{
if (fallbackAction == null)
{
throw new ArgumentNullException(nameof(fallbackAction));
}

Action<DelegateResult<TResult>> doNothing = _ => { };
return policyBuilder.Fallback(fallbackAction, doNothing);
}
=> policyBuilder.Fallback(fallbackAction, EmptyAction);

/// <summary>
/// Builds a <see cref="FallbackPolicy"/> 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 <paramref name="onFallback"/> with details of the handled exception or result; then returns <paramref name="fallbackValue"/>.
Expand Down Expand Up @@ -387,4 +357,9 @@ public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResu
onFallback,
fallbackAction);
}

private static void EmptyAction<T>(DelegateResult<T> result)
{
// No-op
}
}
2 changes: 1 addition & 1 deletion src/Polly/Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyTitle>Polly</AssemblyTitle>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectType>Library</ProjectType>
<MutationScore>97</MutationScore>
<MutationScore>100</MutationScore>
<IncludePollyUsings>true</IncludePollyUsings>
<!-- We do not plan on enabling nullable annotations for Polly -->
<NoWarn>$(NoWarn);RS0037</NoWarn>
Expand Down
Loading
Loading