< Summary

Information
Class: Intentum.Core.Streaming.MemoryBehaviorStreamConsumer
Assembly: Intentum.Core
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Core/Streaming/MemoryBehaviorStreamConsumer.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
PostAsync(...)100%11100%
Complete()100%11100%
ReadAllAsync()100%22100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Core/Streaming/MemoryBehaviorStreamConsumer.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using System.Threading.Channels;
 3
 4namespace Intentum.Core.Streaming;
 5
 6/// <summary>
 7/// In-memory behavior stream consumer: producer posts batches via Post; consumer reads via ReadAllAsync.
 8/// Useful for testing and single-node scenarios.
 9/// </summary>
 10public sealed class MemoryBehaviorStreamConsumer : IBehaviorStreamConsumer
 11{
 212    private readonly Channel<BehaviorEventBatch> _channel = Channel.CreateUnbounded<BehaviorEventBatch>(
 213        new UnboundedChannelOptions { SingleReader = true, SingleWriter = false });
 14
 15    /// <summary>
 16    /// Posts a batch to the stream. Consumers will receive it from ReadAllAsync.
 17    /// </summary>
 18    public ValueTask PostAsync(BehaviorEventBatch batch, CancellationToken cancellationToken = default)
 219    {
 220        return _channel.Writer.WriteAsync(batch, cancellationToken);
 221    }
 22
 23    /// <summary>
 24    /// Completes the writer so ReadAllAsync will finish after all posted batches are read.
 25    /// </summary>
 26    public void Complete()
 227    {
 228        _channel.Writer.Complete();
 229    }
 30
 31    /// <inheritdoc />
 32    public async IAsyncEnumerable<BehaviorEventBatch> ReadAllAsync([EnumeratorCancellation] CancellationToken cancellati
 233    {
 1034        await foreach (var batch in _channel.Reader.ReadAllAsync(cancellationToken))
 235            yield return batch;
 236    }
 37}