<PackageReference Include="Polly.Core" Version="8.5.2" />

ComponentWithDisposeCallbacks

using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Utils.Pipeline { [NullableContext(1)] [Nullable(0)] internal sealed class ComponentWithDisposeCallbacks : PipelineComponent { private readonly List<Action> _callbacks; internal PipelineComponent Component { get; } public ComponentWithDisposeCallbacks(PipelineComponent component, List<Action> callbacks) { Component = component; _callbacks = callbacks; } public override ValueTask DisposeAsync() { ExecuteCallbacks(); return Component.DisposeAsync(); } [return: Nullable(new byte[] { 0, 0, 1 })] internal override ValueTask<Outcome<TResult>> ExecuteCore<[Nullable(2)] TResult, [Nullable(2)] TState>([Nullable(new byte[] { 1, 1, 1, 0, 0, 1 })] Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, ResilienceContext context, TState state) { return Component.ExecuteCore(callback, context, state); } private void ExecuteCallbacks() { foreach (Action callback in _callbacks) { callback(); } _callbacks.Clear(); } } }