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

Rename ExecuteCoreAsync to ExecuteCore #1424

Merged
merged 3 commits into from
Jul 24, 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
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private class TelemetryEventStrategy : ResilienceStrategy

public TelemetryEventStrategy(ResilienceStrategyTelemetry telemetry) => _telemetry = telemetry;

protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Polly.Core.Benchmarks.Utils;

internal class EmptyResilienceStrategy : ResilienceStrategy
{
protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static object CreateCircuitBreaker(PollyVersion technology)

private class OutcomeHandlingStrategy : ResilienceStrategy
{
protected override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/NullResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private NullResilienceStrategy()
}

/// <inheritdoc/>
protected internal override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ abstract Polly.Registry.ResilienceStrategyProvider<TKey>.TryGetStrategy(TKey key
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
abstract Polly.ResilienceStrategy.ExecuteCoreAsync<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>>
abstract Polly.ResilienceStrategy.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>>
override Polly.Outcome<TResult>.ToString() -> string!
override Polly.Registry.ResilienceStrategyRegistry<TKey>.TryGetStrategy(TKey key, out Polly.ResilienceStrategy? strategy) -> bool
override Polly.Registry.ResilienceStrategyRegistry<TKey>.TryGetStrategy<TResult>(TKey key, out Polly.ResilienceStrategy<TResult>? strategy) -> bool
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Execute(Action execute)

try
{
strategy.ExecuteCoreAsync(static (context, state) =>
strategy.ExecuteAsync(static (context, state) =>
{
state();
return new ValueTask<Outcome<VoidResult>>(new(VoidResult.Instance));
Expand Down Expand Up @@ -108,7 +108,7 @@ internal class DelayStrategy : ResilienceStrategy
_timeProvider = timeProvider;
}

protected override async ValueTask<T> ExecuteCoreAsync<T, TState>(
protected override async ValueTask<T> ExecuteCore<T, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<T>>> callback,
ResilienceContext context,
TState state)
Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/ResilienceStrategy.Async.ValueTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async ValueTask ExecuteAsync<TState>(

InitializeAsyncContext(context);

var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -59,7 +59,7 @@ public async ValueTask ExecuteAsync(

InitializeAsyncContext(context);

var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -98,7 +98,7 @@ public async ValueTask ExecuteAsync<TState>(

try
{
var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -139,7 +139,7 @@ public async ValueTask ExecuteAsync(

try
{
var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down
10 changes: 5 additions & 5 deletions src/Polly.Core/ResilienceStrategy.Async.ValueTaskT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ValueTask<Outcome<TResult>> ExecuteOutcomeAsync<TResult, TState>(

InitializeAsyncContext<TResult>(context);

return ExecuteCoreAsync(callback, context, state);
return ExecuteCore(callback, context, state);
}

/// <summary>
Expand All @@ -52,7 +52,7 @@ public async ValueTask<TResult> ExecuteAsync<TResult, TState>(

InitializeAsyncContext<TResult>(context);

var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -87,7 +87,7 @@ public async ValueTask<TResult> ExecuteAsync<TResult>(

InitializeAsyncContext<TResult>(context);

var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -126,7 +126,7 @@ public async ValueTask<TResult> ExecuteAsync<TResult, TState>(

try
{
var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down Expand Up @@ -167,7 +167,7 @@ public async ValueTask<TResult> ExecuteAsync<TResult>(

try
{
var outcome = await ExecuteCoreAsync(
var outcome = await ExecuteCore(
static async (context, state) =>
{
try
Expand Down
20 changes: 12 additions & 8 deletions src/Polly.Core/ResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@ public abstract partial class ResilienceStrategy
internal ResilienceStrategyOptions? Options { get; set; }

/// <summary>
/// Executes the specified callback.
/// An implementation of resilience strategy that executes the specified <paramref name="callback"/>.
/// </summary>
/// <typeparam name="TResult">The type of result returned by the callback.</typeparam>
/// <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 <see cref="ValueTask"/> that represents an asynchronous callback.</returns>
/// <returns>
/// An instance of pending <see cref="ValueTask"/> for asynchronous executions or completed <see cref="ValueTask"/> task for synchronous exexutions.
/// </returns>
/// <remarks>
/// This method is called by various methods exposed on <see cref="ResilienceStrategy"/>. These methods make sure that
/// <paramref name="context"/> is properly initialized with details about the execution mode.
/// <c>This method is called for both synchronous and asynchronous execution flows.</c>
martincostello marked this conversation as resolved.
Show resolved Hide resolved
/// <para>
/// The provided callback never throws an exception. Instead, the exception is captured and converted to an <see cref="Outcome{TResult}"/>.
/// You can use <see cref="ResilienceContext.IsSynchronous"/> to dermine wheether the <paramref name="callback"/> is synchronous or asynchronous one.
/// 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.
/// </para>
/// <para>
/// Do not throw exceptions from your strategy implementation. Instead, return an exception instance as <see cref="Outcome{TResult}"/>.
/// 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 internal abstract ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal abstract ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state);
Expand All @@ -44,7 +48,7 @@ private Outcome<TResult> ExecuteCoreSync<TResult, TState>(
ResilienceContext context,
TState state)
{
return ExecuteCoreAsync(
return ExecuteCore(
static (context, state) =>
{
var result = state.callback(context, state.state);
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Timeout/TimeoutResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public TimeoutResilienceStrategy(TimeoutStrategyOptions options, TimeProvider ti

public Func<OnTimeoutArguments, ValueTask>? OnTimeout { get; }

protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Utils/OutcomeResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected OutcomeResilienceStrategy(bool isGeneric)
_isGeneric = isGeneric;
}

protected internal sealed override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal sealed override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Core/Utils/ReloadableResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public ReloadableResilienceStrategy(

public ResilienceStrategy Strategy { get; private set; }

protected internal override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
{
return Strategy.ExecuteCoreAsync(callback, context, state);
return Strategy.ExecuteCore(callback, context, state);
}

private void RegisterOnReload(CancellationToken previousToken)
Expand Down
10 changes: 5 additions & 5 deletions src/Polly.Core/Utils/ResilienceStrategyPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private ResilienceStrategyPipeline(ResilienceStrategy pipeline, IReadOnlyList<Re

public IReadOnlyList<ResilienceStrategy> Strategies { get; }

protected internal override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context, TState state)
{
Expand All @@ -66,7 +66,7 @@ protected internal override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult
return Outcome.FromExceptionAsTask<TResult>(new OperationCanceledException(context.CancellationToken).TrySetStackTrace());
}

return _pipeline.ExecuteCoreAsync(callback, context, state);
return _pipeline.ExecuteCore(callback, context, state);
}

/// <summary>
Expand All @@ -80,20 +80,20 @@ private sealed class DelegatingResilienceStrategy : ResilienceStrategy

public ResilienceStrategy? Next { get; set; }

protected internal override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
{
return _strategy.ExecuteCoreAsync(
return _strategy.ExecuteCore(
static (context, state) =>
{
if (context.CancellationToken.IsCancellationRequested)
{
return Outcome.FromExceptionAsTask<TResult>(new OperationCanceledException(context.CancellationToken).TrySetStackTrace());
}

return state.Next!.ExecuteCoreAsync(state.callback, context, state.state);
return state.Next!.ExecuteCore(state.callback, context, state.state);
},
context,
(Next, callback, state));
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Utils/TimeProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Task DelayAsync(this TimeProvider timeProvider, TimeSpan delay, Re
// For synchronous scenarios we want to return a completed task. We avoid
// the use of Thread.Sleep() here because it is not cancellable and to
// simplify the code. Sync-over-async is not a concern here because it
// only applies in the case of a reilience event and not on the hot path.
// only applies in the case of a resilience event and not on the hot path.
timeProvider.Delay(delay, context.CancellationToken).GetAwaiter().GetResult();
#pragma warning restore CA1849

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public TelemetryResilienceStrategy(

public Histogram<double> ExecutionDuration { get; }

protected override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.RateLimiting/RateLimiterResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public RateLimiterResilienceStrategy(

public Func<OnRateLimiterRejectedArguments, ValueTask>? OnLeaseRejected { get; }

protected override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
4 changes: 2 additions & 2 deletions test/Polly.Core.Tests/ResilienceStrategyBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private class Strategy : ResilienceStrategy

public Action? After { get; set; }

protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand All @@ -432,7 +432,7 @@ private class ExecuteCallbackTwiceStrategy : ResilienceStrategy

public Action? After { get; set; }

protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task CreatePipeline_EnsureExceptionsNotWrapped()

var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies);
await pipeline
.Invoking(p => p.ExecuteCoreAsync((_, _) => Outcome.FromResultAsTask(10), ResilienceContextPool.Shared.Get(), "state").AsTask())
.Invoking(p => p.ExecuteCore((_, _) => Outcome.FromResultAsTask(10), ResilienceContextPool.Shared.Get(), "state").AsTask())
.Should()
.ThrowAsync<NotSupportedException>();
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task CreatePipeline_CancelledLater_EnsureNoExecution()

private class Strategy : ResilienceStrategy
{
protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private ResilienceStrategyProvider<string> CreateProvider()

private class TestStrategy : ResilienceStrategy
{
protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state) => new(Outcome.FromException<TResult>(new NotSupportedException()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private class ServiceProviderStrategy : ResilienceStrategy

public ServiceProviderStrategy(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ReloadableStrategy : ResilienceStrategy

public string Tag { get; }

protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
2 changes: 1 addition & 1 deletion test/Polly.TestUtils/TestResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TestResilienceStrategy : ResilienceStrategy

public Func<ResilienceContext, object?, Task>? OnExecute { get; set; }

protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
protected internal override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void GetInnerStrategies_Reloadable_Ok()

private sealed class CustomStrategy : ResilienceStrategy
{
protected override ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state)
=> throw new NotSupportedException();
}
}