< Summary

Information
Class: CounterpointCollective.Dataflow.BoundedPropagatorBlock<T1, T2>
Assembly: Dataflow.Composable
File(s): /builds/counterpointcollective/composabledataflowblocks/Source/Dataflow.Composable/DataFlow/BoundedPropagatorBlock.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 74
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_SourceSide()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
ConsumeMessage(...)100%11100%
LinkTo(...)100%11100%
ReleaseReservation(...)100%11100%
ReserveMessage(...)100%11100%
TryReceive(...)100%44100%
TryReceiveAll(...)100%44100%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Threading.Tasks.Dataflow;
 3
 4namespace CounterpointCollective.Dataflow
 5{
 6    /// <summary>
 7    /// A wrapper that enforces a <see cref="BoundedTargetBlock{I}.BoundedCapacity">BoundedCapacity</see> on an
 8    /// arbitrary <see cref="IPropagatorBlock{I,O}"/>. See also its base class <see cref="BoundedTargetBlock{I}"/>.
 9    /// </summary>
 10
 11    public class BoundedPropagatorBlock<I,O> : BoundedTargetBlock<I>, IReceivableSourceBlock<O>, IResizablePropagatorBlo
 12    {
 1568213        private ISourceBlock<O> SourceSide { get; }
 14        public BoundedPropagatorBlock(
 15            IPropagatorBlock<I, O> inner,
 16            int boundedCapacity = DataflowBlockOptions.Unbounded,
 17            Action? onEntering = null,
 18            Action? onEntered = null
 14219        ) : base(inner, boundedCapacity, onEntering, onEntered) => SourceSide = CreateExit(inner);
 20
 21        public BoundedPropagatorBlock(
 22            ITargetBlock<I> entrance,
 23            ISourceBlock<O> exit,
 24            int boundedCapacity = DataflowBlockOptions.Unbounded,
 25            Action? onEntering = null,
 26            Action? onEntered = null
 3727        ) : this(DataflowBlock.Encapsulate(entrance, exit), boundedCapacity, onEntering, onEntered)
 28        {
 3729        }
 30
 31        /// <exclude />
 32        public O? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<O> target, out bool messageConsumed)
 1133            => SourceSide.ConsumeMessage(messageHeader, target, out messageConsumed);
 34
 35        /// <exclude />
 36        public IDisposable LinkTo(ITargetBlock<O> target, DataflowLinkOptions linkOptions)
 34837            => SourceSide.LinkTo(target, linkOptions);
 38
 39        /// <exclude />
 40        public void ReleaseReservation(DataflowMessageHeader messageHeader, ITargetBlock<O> target)
 241            => SourceSide.ReleaseReservation(messageHeader, target);
 42
 43        /// <exclude />
 44        public bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock<O> target)
 1345            => SourceSide.ReserveMessage(messageHeader, target);
 46
 47        /// <exclude />
 48        public bool TryReceive(Predicate<O>? filter, [MaybeNullWhen(false)] out O item)
 49        {
 1483250            if (SourceSide is IReceivableSourceBlock<O> r && r.TryReceive(filter, out item))
 51            {
 1470852                return true;
 53            }
 54            else
 55            {
 12456                item = default;
 12457                return false;
 58            }
 59        }
 60
 61        /// <exclude />
 62        public bool TryReceiveAll([NotNullWhen(true)] out IList<O>? items) {
 47663            if (SourceSide is IReceivableSourceBlock<O> r && r.TryReceiveAll(out items))
 64            {
 28065                return true;
 66            }
 67            else
 68            {
 19669                items = null;
 19670                return false;
 71            }
 72        }
 73    }
 74}