< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Collectors.AgentOutputCollectorAccessor<T>
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Collectors/AgentOutputCollectorAccessor.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 40
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_Current()100%11100%
BeginScope()100%11100%
BeginScope(...)100%11100%
.ctor(...)100%11100%
Dispose()50%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Collectors/AgentOutputCollectorAccessor.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Collectors;
 2
 3/// <summary>
 4/// <see cref="AsyncLocal{T}"/>-backed implementation of <see cref="IAgentOutputCollectorAccessor{T}"/>.
 5/// Uses the mutable-holder pattern so items added by tools in child async flows are visible
 6/// to the parent scope.
 7/// </summary>
 8internal sealed class AgentOutputCollectorAccessor<T> : IAgentOutputCollectorAccessor<T>
 9{
 110    private static readonly AsyncLocal<IAgentOutputCollector<T>?> CurrentCollector = new();
 11
 12    /// <inheritdoc />
 1513    public IAgentOutputCollector<T>? Current => CurrentCollector.Value;
 14
 15    /// <inheritdoc />
 16    public IDisposable BeginScope() =>
 617        BeginScope(new AgentOutputCollector<T>());
 18
 19    /// <inheritdoc />
 20    public IDisposable BeginScope(IAgentOutputCollector<T> collector)
 21    {
 822        ArgumentNullException.ThrowIfNull(collector);
 23
 724        var previous = CurrentCollector.Value;
 725        CurrentCollector.Value = collector;
 726        return new Scope(previous);
 27    }
 28
 729    private sealed class Scope(IAgentOutputCollector<T>? previous) : IDisposable
 30    {
 31        private bool _disposed;
 32
 33        public void Dispose()
 34        {
 735            if (_disposed) return;
 736            _disposed = true;
 737            CurrentCollector.Value = previous;
 738        }
 39    }
 40}