Skip to content

Commit e316681

Browse files
committed
API Review Feedback
1 parent 69e5f16 commit e316681

31 files changed

+60
-202
lines changed

bench/Polly.Core.Benchmarks/BridgeBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BridgeBenchmark
99
public void Setup()
1010
{
1111
_policy = Policy.NoOpAsync<string>();
12-
_policyWrapped = ResiliencePipeline<string>.Null.AsAsyncPolicy();
12+
_policyWrapped = ResiliencePipeline<string>.Empty.AsAsyncPolicy();
1313
}
1414

1515
[Benchmark(Baseline = true)]

bench/Polly.Core.Benchmarks/ResiliencePipelineBenchmark.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,48 @@ public class ResiliencePipelineBenchmark
1010
public async ValueTask ExecuteOutcomeAsync()
1111
{
1212
var context = ResilienceContextPool.Shared.Get();
13-
await ResiliencePipeline.Null.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
13+
await ResiliencePipeline.Empty.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
1414
ResilienceContextPool.Shared.Return(context);
1515
}
1616

1717
[Benchmark]
1818
public async ValueTask ExecuteAsync_ResilienceContextAndState()
1919
{
2020
var context = ResilienceContextPool.Shared.Get();
21-
await ResiliencePipeline.Null.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
21+
await ResiliencePipeline.Empty.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
2222
ResilienceContextPool.Shared.Return(context);
2323
}
2424

2525
[Benchmark]
2626
public async ValueTask ExecuteAsync_CancellationToken()
2727
{
28-
await ResiliencePipeline.Null.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
28+
await ResiliencePipeline.Empty.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
2929
}
3030

3131
[Benchmark]
3232
public async ValueTask ExecuteAsync_GenericStrategy_CancellationToken()
3333
{
34-
await ResiliencePipeline<string>.Null.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
34+
await ResiliencePipeline<string>.Empty.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
3535
}
3636

3737
[Benchmark]
3838
public void Execute_ResilienceContextAndState()
3939
{
4040
var context = ResilienceContextPool.Shared.Get();
41-
ResiliencePipeline.Null.Execute((_, _) => "dummy", context, "state");
41+
ResiliencePipeline.Empty.Execute((_, _) => "dummy", context, "state");
4242
ResilienceContextPool.Shared.Return(context);
4343
}
4444

4545
[Benchmark]
4646
public void Execute_CancellationToken()
4747
{
48-
ResiliencePipeline.Null.Execute(_ => "dummy", CancellationToken.None);
48+
ResiliencePipeline.Empty.Execute(_ => "dummy", CancellationToken.None);
4949
}
5050

5151
[Benchmark]
5252
public void Execute_GenericStrategy_CancellationToken()
5353
{
54-
ResiliencePipeline<string>.Null.Execute(_ => "dummy", CancellationToken.None);
54+
ResiliencePipeline<string>.Empty.Execute(_ => "dummy", CancellationToken.None);
5555
}
5656

5757
public class NonGenericStrategy

src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,6 @@ private void UpdateOriginalContext()
207207
if (Tasks.FirstOrDefault(static t => t.IsAccepted) is TaskExecution<T> acceptedExecution)
208208
{
209209
originalContext.Properties.Replace(acceptedExecution.Properties);
210-
211-
if (acceptedExecution.Type == HedgedTaskType.Secondary)
212-
{
213-
foreach (var @event in acceptedExecution.Context.ResilienceEvents)
214-
{
215-
originalContext.AddResilienceEvent(@event);
216-
}
217-
}
218210
}
219211
}
220212

src/Polly.Core/Outcome.TResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ private Outcome(ExceptionDispatchInfo exceptionDispatchInfo)
4444
/// <remarks>
4545
/// Returns <see langword="true"/> even if the result is void. Use <see cref="IsVoidResult"/> to check for void results.
4646
/// </remarks>
47-
public bool HasResult => ExceptionDispatchInfo is null;
47+
internal bool HasResult => ExceptionDispatchInfo is null;
4848

4949
/// <summary>
5050
/// Gets a value indicating whether the operation produced a void result.
5151
/// </summary>
52-
public bool IsVoidResult => Result is VoidResult;
52+
internal bool IsVoidResult => Result is VoidResult;
5353

5454
/// <summary>
5555
/// Throws an exception if the operation produced an exception.
@@ -64,7 +64,7 @@ private Outcome(ExceptionDispatchInfo exceptionDispatchInfo)
6464
/// </summary>
6565
/// <param name="result">Output parameter for the result.</param>
6666
/// <returns><see langword="true"/> if the result is available; <see langword="false"/> otherwise.</returns>
67-
public bool TryGetResult(out TResult? result)
67+
internal bool TryGetResult(out TResult? result)
6868
{
6969
if (HasResult && !IsVoidResult)
7070
{

src/Polly.Core/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,8 @@ Polly.Outcome
134134
Polly.Outcome<TResult>
135135
Polly.Outcome<TResult>.EnsureSuccess() -> void
136136
Polly.Outcome<TResult>.Exception.get -> System.Exception?
137-
Polly.Outcome<TResult>.HasResult.get -> bool
138-
Polly.Outcome<TResult>.IsVoidResult.get -> bool
139137
Polly.Outcome<TResult>.Outcome() -> void
140138
Polly.Outcome<TResult>.Result.get -> TResult?
141-
Polly.Outcome<TResult>.TryGetResult(out TResult? result) -> bool
142139
Polly.OutcomeArguments<TResult, TArgs>
143140
Polly.OutcomeArguments<TResult, TArgs>.Arguments.get -> TArgs
144141
Polly.OutcomeArguments<TResult, TArgs>.Context.get -> Polly.ResilienceContext!
@@ -193,7 +190,6 @@ Polly.ResilienceContext.CancellationToken.get -> System.Threading.CancellationTo
193190
Polly.ResilienceContext.ContinueOnCapturedContext.get -> bool
194191
Polly.ResilienceContext.OperationKey.get -> string?
195192
Polly.ResilienceContext.Properties.get -> Polly.ResilienceProperties!
196-
Polly.ResilienceContext.ResilienceEvents.get -> System.Collections.Generic.IReadOnlyList<Polly.Telemetry.ResilienceEvent>!
197193
Polly.ResilienceContextCreationArguments
198194
Polly.ResilienceContextCreationArguments.CancellationToken.get -> System.Threading.CancellationToken
199195
Polly.ResilienceContextCreationArguments.ContinueOnCapturedContext.get -> bool?
@@ -406,7 +402,7 @@ static Polly.RetryResiliencePipelineBuilderExtensions.AddRetry(this Polly.Resili
406402
static Polly.RetryResiliencePipelineBuilderExtensions.AddRetry<TResult>(this Polly.ResiliencePipelineBuilder<TResult>! builder, Polly.Retry.RetryStrategyOptions<TResult>! options) -> Polly.ResiliencePipelineBuilder<TResult>!
407403
static Polly.TimeoutResiliencePipelineBuilderExtensions.AddTimeout<TBuilder>(this TBuilder! builder, Polly.Timeout.TimeoutStrategyOptions! options) -> TBuilder!
408404
static Polly.TimeoutResiliencePipelineBuilderExtensions.AddTimeout<TBuilder>(this TBuilder! builder, System.TimeSpan timeout) -> TBuilder!
409-
static readonly Polly.ResiliencePipeline.Null -> Polly.ResiliencePipeline!
410-
static readonly Polly.ResiliencePipeline<T>.Null -> Polly.ResiliencePipeline<T>!
405+
static readonly Polly.ResiliencePipeline.Empty -> Polly.ResiliencePipeline!
406+
static readonly Polly.ResiliencePipeline<T>.Empty -> Polly.ResiliencePipeline<T>!
411407
virtual Polly.Registry.ResiliencePipelineProvider<TKey>.GetPipeline(TKey key) -> Polly.ResiliencePipeline!
412408
virtual Polly.Registry.ResiliencePipelineProvider<TKey>.GetPipeline<TResult>(TKey key) -> Polly.ResiliencePipeline<TResult>!

src/Polly.Core/ResilienceContext.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Diagnostics.CodeAnalysis;
2-
using Polly.Telemetry;
32

43
namespace Polly;
54

@@ -14,8 +13,6 @@ namespace Polly;
1413
/// </remarks>
1514
public sealed class ResilienceContext
1615
{
17-
private readonly List<ResilienceEvent> _resilienceEvents = new();
18-
1916
internal ResilienceContext()
2017
{
2118
}
@@ -66,24 +63,13 @@ internal ResilienceContext()
6663
/// </summary>
6764
public ResilienceProperties Properties { get; internal set; } = new();
6865

69-
/// <summary>
70-
/// Gets the collection of resilience events that occurred while executing the resilience strategy.
71-
/// </summary>
72-
/// <remarks>
73-
/// If the number of resilience events with severity greater than <see cref="ResilienceEventSeverity.Information"/> is greater than zero it's an indication that the execution was unhealthy.
74-
/// Note that the number of reported events depends on whether telemetry is enabled for the pipeline or not.
75-
/// </remarks>
76-
public IReadOnlyList<ResilienceEvent> ResilienceEvents => _resilienceEvents;
77-
7866
internal void InitializeFrom(ResilienceContext context)
7967
{
8068
OperationKey = context.OperationKey;
8169
ResultType = context.ResultType;
8270
IsSynchronous = context.IsSynchronous;
8371
CancellationToken = context.CancellationToken;
8472
ContinueOnCapturedContext = context.ContinueOnCapturedContext;
85-
_resilienceEvents.Clear();
86-
_resilienceEvents.AddRange(context.ResilienceEvents);
8773
}
8874

8975
[ExcludeFromCodeCoverage]
@@ -101,11 +87,6 @@ internal ResilienceContext Initialize<TResult>(bool isSynchronous)
10187
return this;
10288
}
10389

104-
internal void AddResilienceEvent(ResilienceEvent @event)
105-
{
106-
_resilienceEvents.Add(@event);
107-
}
108-
10990
internal bool Reset()
11091
{
11192
OperationKey = null;
@@ -114,7 +95,6 @@ internal bool Reset()
11495
ContinueOnCapturedContext = false;
11596
CancellationToken = default;
11697
Properties.Options.Clear();
117-
_resilienceEvents.Clear();
11898
return true;
11999
}
120100

src/Polly.Core/ResiliencePipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed partial class ResiliencePipeline
1414
/// <summary>
1515
/// Resilience pipeline that executes the user-provided callback without any additional logic.
1616
/// </summary>
17-
public static readonly ResiliencePipeline Null = new(PipelineComponent.Null, DisposeBehavior.Ignore);
17+
public static readonly ResiliencePipeline Empty = new(PipelineComponent.Empty, DisposeBehavior.Ignore);
1818

1919
internal ResiliencePipeline(PipelineComponent component, DisposeBehavior disposeBehavior)
2020
{

src/Polly.Core/ResiliencePipelineBuilderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ internal PipelineComponent BuildPipelineComponent()
114114

115115
if (components.Count == 0)
116116
{
117-
return PipelineComponent.Null;
117+
return PipelineComponent.Empty;
118118
}
119119

120120
var source = new ResilienceTelemetrySource(Name, InstanceName, null);

src/Polly.Core/ResiliencePipelineT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed partial class ResiliencePipeline<T>
1515
/// <summary>
1616
/// Resilience pipeline that executes the user-provided callback without any additional logic.
1717
/// </summary>
18-
public static readonly ResiliencePipeline<T> Null = new(PipelineComponent.Null, DisposeBehavior.Ignore);
18+
public static readonly ResiliencePipeline<T> Empty = new(PipelineComponent.Empty, DisposeBehavior.Ignore);
1919

2020
internal ResiliencePipeline(PipelineComponent component, DisposeBehavior disposeBehavior)
2121
{

src/Polly.Core/Telemetry/ResilienceStrategyTelemetry.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public void Report<TArgs>(ResilienceEvent resilienceEvent, ResilienceContext con
3333
{
3434
Guard.NotNull(context);
3535

36-
context.AddResilienceEvent(resilienceEvent);
37-
3836
if (Listener is null || resilienceEvent.Severity == ResilienceEventSeverity.None)
3937
{
4038
return;
@@ -52,8 +50,6 @@ public void Report<TArgs>(ResilienceEvent resilienceEvent, ResilienceContext con
5250
/// <param name="args">The event arguments.</param>
5351
public void Report<TArgs, TResult>(ResilienceEvent resilienceEvent, OutcomeArguments<TResult, TArgs> args)
5452
{
55-
args.Context.AddResilienceEvent(resilienceEvent);
56-
5753
if (Listener is null || resilienceEvent.Severity == ResilienceEventSeverity.None)
5854
{
5955
return;

0 commit comments

Comments
 (0)