< Summary

Information
Class: Intentum.Runtime.Resilience.Bulkhead.MemoryBulkhead
Assembly: Intentum.Runtime
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Runtime/Resilience/Bulkhead/MemoryBulkhead.cs
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 37
Line coverage: 94.7%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
ExecuteAsync()100%44100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Runtime/Resilience/Bulkhead/MemoryBulkhead.cs

#LineLine coverage
 1using Intentum.Runtime.Resilience.Exceptions;
 2
 3namespace Intentum.Runtime.Resilience.Bulkhead;
 4
 5public sealed class MemoryBulkhead : IBulkhead
 6{
 7    private readonly BulkheadOptions _options;
 8    private readonly SemaphoreSlim _semaphore;
 9
 610    public MemoryBulkhead(BulkheadOptions options)
 611    {
 612        _options = options;
 613        var max = Math.Max(1, options.MaxParallelization);
 614        _semaphore = new SemaphoreSlim(max, max);
 615    }
 16
 217    public int AvailableSlots => _semaphore.CurrentCount;
 018    public int QueueSize => _options.MaxParallelization - _semaphore.CurrentCount;
 19
 20    public async Task<T> ExecuteAsync<T>(Func<Task<T>> operation, CancellationToken cancellationToken = default)
 921    {
 922        if (_options.MaxParallelization <= 0)
 123            throw new BulkheadFullException();
 24
 825        if (!await _semaphore.WaitAsync(_options.QueueTimeout, cancellationToken))
 126            throw new BulkheadFullException();
 27
 28        try
 629        {
 630            return await operation();
 31        }
 32        finally
 533        {
 534            _semaphore.Release();
 535        }
 536    }
 37}