< Summary

Information
Class: CounterpointCollective.Dataflow.TeeBlock<T1, T2, T3>
Assembly: Dataflow.Composable
File(s): /builds/counterpointcollective/composabledataflowblocks/Source/Dataflow.Composable/DataFlow/TeeBlock.cs
Line coverage
96%
Covered lines: 32
Uncovered lines: 1
Coverable lines: 33
Total lines: 50
Line coverage: 96.9%
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
get_TargetSide()100%11100%
get_SourceSide()100%11100%
get_Count()100%11100%
.ctor(...)50%2296.66%

File(s)

/builds/counterpointcollective/composabledataflowblocks/Source/Dataflow.Composable/DataFlow/TeeBlock.cs

#LineLine coverage
 1using CounterpointCollective.Dataflow.Encapsulation;
 2using CounterpointCollective.Dataflow.Fluent;
 3using System.Collections.Concurrent;
 4using System.Threading.Tasks.Dataflow;
 5
 6namespace CounterpointCollective.Dataflow
 7{
 8    public class TeeBlock<I, T, O> : AbstractEncapsulatedPropagatorBlock<I, O>
 9    {
 10        private BoundedPropagatorBlock<I, O> b;
 10411        protected override ITargetBlock<I> TargetSide => b;
 12
 12213        protected override ISourceBlock<O> SourceSide => b;
 14
 115        public int Count => b.Count;
 16
 217        public TeeBlock(IPropagatorBlock<I, T> inner, Func<I, T, O> combinator, DataflowBlockOptions options)
 18        {
 219            var q = new ConcurrentQueue<I>();
 20
 221            b =
 222                new TransformBlock<I, I>(h =>
 223                {
 10224                    q.Enqueue(h);
 10225                    return h;
 226                }, new() { CancellationToken = options.CancellationToken, SingleProducerConstrained = true })
 227                .Pipeline()
 228                .LinkTo(inner, new() { PropagateCompletion = true })
 229                .Transform(
 230                    t =>
 231                    {
 10232                        if (q.TryDequeue(out var i))
 233                        {
 10234                            return combinator(i, t);
 235                        } else
 236                        {
 037                            throw new InvalidOperationException("Tee inner block must produce exactly 1 output message p
 238                        }
 239                    },
 240                    new ExecutionDataflowBlockOptions()
 241                    {
 242                        CancellationToken = options.CancellationToken,
 243                        SingleProducerConstrained = true
 244                    }
 245                )
 246                .Build()
 247                .WithBoundedCapacity(options.BoundedCapacity);
 248        }
 49    }
 50}