Пример #1
0
        internal static bool TenTransformsToAction()
        {
            const int ITERS = 2;
            var       first = new TransformBlock <int, int>(item => item);

            TransformBlock <int, int> t = first;

            for (int i = 0; i < 9; i++)
            {
                var next = new TransformBlock <int, int>(item => item);
                t.LinkWithCompletion(next);
                t = next;
            }
            int completedCount = 0;
            var last           = new ActionBlock <int>(i => completedCount++);

            t.LinkWithCompletion(last);

            for (int i = 0; i < ITERS; i++)
            {
                first.Post(i);
            }
            first.Complete();
            last.Completion.Wait();

            return(completedCount == ITERS);
        }
Пример #2
0
        internal static bool TransformToAction()
        {
            bool      passed = true;
            const int ITERS  = 2;

            var t = new TransformBlock <int, int>(i => i * 2);
            int completedCount = 0;
            int prev           = -2;
            var c = new ActionBlock <int>(i =>
            {
                completedCount++;
                if (i != prev + 2)
                {
                    passed &= false;
                }
                prev = i;
            });

            t.LinkWithCompletion(c);

            for (int i = 0; i < ITERS; i++)
            {
                t.Post(i);
            }
            t.Complete();
            c.Completion.Wait();
            Assert.True(completedCount == ITERS);

            return(passed);
        }
Пример #3
0
        internal static bool TransformToAction()
        {
            bool passed = true;
            const int ITERS = 2;

            var t = new TransformBlock<int, int>(i => i * 2);
            int completedCount = 0;
            int prev = -2;
            var c = new ActionBlock<int>(i =>
            {
                completedCount++;
                if (i != prev + 2) passed &= false;
                prev = i;
            });
            t.LinkWithCompletion(c);

            for (int i = 0; i < ITERS; i++) t.Post(i);
            t.Complete();
            c.Completion.Wait();
            Assert.True(completedCount == ITERS);

            return passed;
        }