<PackageReference Include="Polly" Version="8.4.0" />

BulkheadEngine

static class BulkheadEngine
using System; using System.Runtime.CompilerServices; using System.Threading; namespace Polly.Bulkhead { internal static class BulkheadEngine { [System.Runtime.CompilerServices.NullableContext(1)] internal static TResult Implementation<[System.Runtime.CompilerServices.Nullable(2)] TResult>(Func<Context, CancellationToken, TResult> action, Context context, Action<Context> onBulkheadRejected, SemaphoreSlim maxParallelizationSemaphore, SemaphoreSlim maxQueuedActionsSemaphore, CancellationToken cancellationToken) { if (maxQueuedActionsSemaphore.Wait(TimeSpan.Zero, cancellationToken)) try { maxParallelizationSemaphore.Wait(cancellationToken); try { return action(context, cancellationToken); } finally { maxParallelizationSemaphore.Release(); } } finally { maxQueuedActionsSemaphore.Release(); } onBulkheadRejected(context); throw new BulkheadRejectedException(); } } }