none
Dataflow Pipeline hanging RRS feed

  • Question

  • I am creating a fairly simple pipeline, but can't understand why it is not working.

    Expectation: The pipeline displays each word, then word and its length, and finishes.

    Reality: The pipeline prints out each word, length calculators get called - and the pipeline hangs.

        public class TestPipeline
        {
            private ITargetBlock<int> m_head;
            private ITargetBlock<Tuple<string, int>> m_tail;

            public TestPipeline()
            {
                var start = new TransformManyBlock<int, string>(value => MakeStrings(value));

                var print_plain = new ActionBlock<string>(value => Console.WriteLine($"Plain value: {value}"));
                var map_to_num_letters = new TransformBlock<string, int>(value => StrToNumLetters(value));

                var join_word_to_length = new JoinBlock<string, int>(new GroupingDataflowBlockOptions
                {
                    Greedy = false
                });

                var broacast = new BroadcastBlock<string>(null);

                var sink = new ActionBlock<Tuple<string, int>>(t => ReceiverOfStringAndItsLength(t.Item1, t.Item2));

                start.LinkTo(broacast);

                broacast.LinkTo(map_to_num_letters);
                broacast.LinkTo(print_plain);

                broacast.LinkTo(join_word_to_length.Target1);
                map_to_num_letters.LinkTo(join_word_to_length.Target2);

                m_head = start;
                m_tail = sink;
            }

            public void Start()
            {
                m_head.Post(5);

                m_head.Complete();
                m_tail.Completion.Wait();
            }

            private void ReceiverOfStringAndItsLength(string s, int l)
            {
                Console.WriteLine($"String {s} has {l} letters");
            }

            private int StrToNumLetters(string value)
            {
    //            Console.WriteLine($"String {value} has {value.Length} letters");
                return value.Length;
            }

            private IList<string> MakeStrings(int num_strings)
            {
                var strings = Enumerable.Select(Enumerable.Range(0, num_strings), val =>
                {
                    return GenUtil.RandString(5);
                }).ToList();

                return strings;
            }
        }

    Friday, June 2, 2017 8:57 PM