Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReactiveResilienceStrategy public #1460

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/Polly.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
abstract Polly.ReactiveResilienceStrategy<T>.ExecuteCore<TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<T>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<T>>
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy<TResult>(TKey key, out Polly.ResilienceStrategy<TResult>? strategy) -> bool
abstract Polly.ResilienceContextPool.Get(string? operationKey, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Polly.ResilienceContext!
abstract Polly.ResilienceContextPool.Return(Polly.ResilienceContext! context) -> void
Expand All @@ -10,6 +11,7 @@ override Polly.ResiliencePropertyKey<TValue>.Equals(object? obj) -> bool
override Polly.ResiliencePropertyKey<TValue>.GetHashCode() -> int
override Polly.ResiliencePropertyKey<TValue>.ToString() -> string!
override Polly.Telemetry.ResilienceEvent.ToString() -> string!
override sealed Polly.ReactiveResilienceStrategy<T>.ExecuteCore<TResult, TState>(System.Func<Polly.ResilienceContext!, TState, System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask<Polly.Outcome<TResult>>
Polly.CircuitBreaker.BrokenCircuitException
Polly.CircuitBreaker.BrokenCircuitException.BrokenCircuitException() -> void
Polly.CircuitBreaker.BrokenCircuitException.BrokenCircuitException(string! message) -> void
Expand Down Expand Up @@ -177,6 +179,8 @@ Polly.PredicateBuilder<TResult>.HandleResult(System.Func<TResult, bool>! predica
Polly.PredicateBuilder<TResult>.HandleResult(TResult result, System.Collections.Generic.IEqualityComparer<TResult>? comparer = null) -> Polly.PredicateBuilder<TResult>!
Polly.PredicateBuilder<TResult>.PredicateBuilder() -> void
Polly.PredicateResult
Polly.ReactiveResilienceStrategy<T>
Polly.ReactiveResilienceStrategy<T>.ReactiveResilienceStrategy() -> void
Polly.Registry.ConfigureBuilderContext<TKey>
Polly.Registry.ConfigureBuilderContext<TKey>.BuilderInstanceName.get -> string?
Polly.Registry.ConfigureBuilderContext<TKey>.BuilderName.get -> string!
Expand Down
38 changes: 31 additions & 7 deletions src/Polly.Core/ReactiveResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,43 @@

/// <summary>
/// This base strategy class is used to simplify the implementation of generic (reactive)
/// strategies by limiting the number of generic types this strategy receives.
/// strategies by limiting the number of generic types the execute method receives.
/// </summary>
/// <typeparam name="T">The type of result this strategy handles.</typeparam>
/// <remarks>
/// For strategies that handle all result types the generic parameter must be of type <see cref="object"/>.
/// </remarks>
internal abstract class ReactiveResilienceStrategy<T> : ResilienceStrategy
public abstract class ReactiveResilienceStrategy<T> : ResilienceStrategy
{
/// <summary>
/// An implementation of resilience strategy that executes the specified <paramref name="callback"/>.
/// </summary>
/// <typeparam name="TState">The type of state associated with the callback.</typeparam>
/// <param name="callback">The user-provided callback.</param>
/// <param name="context">The context associated with the callback.</param>
/// <param name="state">The state associated with the callback.</param>
/// <returns>
/// An instance of pending <see cref="ValueTask"/> for asynchronous executions or completed <see cref="ValueTask"/> task for synchronous executions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An instance of pending <see cref="ValueTask"/> for asynchronous executions or completed <see cref="ValueTask"/> task for synchronous executions.
/// An instance of a pending <see cref="ValueTask"/> for asynchronous executions or a completed <see cref="ValueTask"/> task for synchronous executions.

/// </returns>
/// <remarks>
/// <strong>This method is called for both synchronous and asynchronous execution flows.</strong>
/// <para>
/// You can use <see cref="ResilienceContext.IsSynchronous"/> to determine whether the <paramref name="callback"/> is synchronous or asynchronous one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// You can use <see cref="ResilienceContext.IsSynchronous"/> to determine whether the <paramref name="callback"/> is synchronous or asynchronous one.
/// You can use <see cref="ResilienceContext.IsSynchronous"/> to determine whether <paramref name="callback"/> is synchronous or asynchronous.

/// This is useful when the custom strategy behaves differently in each execution flow. In general, for most strategies, the implementation
/// is the same for both execution flows.
/// See <seealso href="https://github.com/App-vNext/Polly/blob/main/src/Polly.Core/README.md#about-synchronous-and-asynchronous-executions"/> for more details.
/// </para>
/// <para>
/// The provided callback never throws an exception. Instead, the exception is captured and converted to an <see cref="Outcome{TResult}"/>.
/// Similarly, do not throw exceptions from your strategy implementation. Instead, return an exception instance as <see cref="Outcome{TResult}"/>.
/// </para>
/// </remarks>
protected abstract ValueTask<Outcome<T>> ExecuteCore<TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<T>>> callback,
ResilienceContext context,
TState state);

/// <inheritdoc/>
protected internal sealed override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
Expand All @@ -36,9 +65,4 @@ static async (context, state) =>
return TaskHelper.ConvertValueTask<T, TResult>(valueTask, context);
}
}

protected abstract ValueTask<Outcome<T>> ExecuteCore<TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<T>>> callback,
ResilienceContext context,
TState state);
}