< Summary

Information
Class: CounterpointCollective.Dataflow.IEnumerableExtensions
Assembly: Dataflow.Composable
File(s): /builds/counterpointcollective/composabledataflowblocks/Source/Dataflow.Composable/DataFlow/IEnumerableExtensions.cs
Line coverage
68%
Covered lines: 13
Uncovered lines: 6
Coverable lines: 19
Total lines: 72
Line coverage: 68.4%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AsSourceBlock(...)100%11100%
AsSourceBlock(...)100%11100%
AsSourceBlock(...)100%210%
AsSourceBlock(...)100%11100%
FeedTo(...)100%210%
FeedTo()87.5%10866.66%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using System.Threading.Tasks.Dataflow;
 6
 7namespace CounterpointCollective.Dataflow
 8{
 9    public static class IEnumerableExtensions
 10    {
 11        public static BufferBlock<I> AsSourceBlock<I>(this IEnumerable<I> source) =>
 912            AsSourceBlock(source, true);
 13
 14        public static BufferBlock<I> AsSourceBlock<I>(this IEnumerable<I> source, bool complete) =>
 915            source.AsSourceBlock(new DataflowBlockOptions(), complete);
 16
 17        public static BufferBlock<I> AsSourceBlock<I>(
 18            this IEnumerable<I> source,
 19            DataflowBlockOptions options
 020        ) => AsSourceBlock(source, options, true);
 21
 22        public static BufferBlock<I> AsSourceBlock<I>(
 23            this IEnumerable<I> source,
 24            DataflowBlockOptions options,
 25            bool complete
 26        )
 27        {
 928            var bufferBlock = new BufferBlock<I>(options);
 929            _ = source.FeedTo(bufferBlock, complete, options.CancellationToken);
 930            return bufferBlock;
 31        }
 32
 33        public static Task FeedTo<T>(
 34            this IEnumerable<T> source,
 35            ITargetBlock<T> target,
 36            CancellationToken cancel = default
 037        ) => FeedTo(source, target, true, cancel);
 38
 39        public static async Task FeedTo<T>(
 40            this IEnumerable<T> source,
 41            ITargetBlock<T> target,
 42            bool complete,
 43            CancellationToken cancel = default
 44        )
 45        {
 46            try
 47            {
 220627048                foreach (var e in source)
 49                {
 110312650                    var consumed = await target.SendAsync(e, cancel);
 110312651                    if (cancel.IsCancellationRequested)
 52                    {
 53                        break;
 54                    }
 55
 110312656                    if (!consumed)
 57                    {
 058                        throw new ArgumentException("Target does not accept message");
 59                    }
 60                }
 961                if (complete)
 62                {
 963                    target.Complete();
 64                }
 965            }
 066            catch (Exception e)
 67            {
 068                target.Fault(e);
 069            }
 970        }
 71    }
 72}