示例#1
0
        public void SwitchCOnCellLoop()
        {
            ValueTuple <DiscreteCell <int>, DiscreteCellSink <int>, DiscreteCellSink <int>, DiscreteCellSink <DiscreteCell <int> > > t = Transaction.Run(() =>
            {
                DiscreteCellLoop <DiscreteCell <int> > loop = DiscreteCell.CreateLoop <DiscreteCell <int> >();
                DiscreteCellSink <int> c1 = DiscreteCell.CreateSink(1);
                DiscreteCellSink <int> c2 = DiscreteCell.CreateSink(11);
                DiscreteCell <int> c      = loop.SwitchC();
                DiscreteCellSink <DiscreteCell <int> > s = DiscreteCell.CreateSink(c1.AsDiscreteCell());
                loop.Loop(s);
                return(ValueTuple.Create(c, c1, c2, s));
            });

            List <int> output = new List <int>();
            IListener  l      = t.Item1.Listen(output.Add);

            t.Item2.Send(2);
            t.Item3.Send(12);

            Transaction.RunVoid(() =>
            {
                t.Item2.Send(3);
                t.Item3.Send(13);
                t.Item4.Send(t.Item3);
            });

            t.Item2.Send(4);
            t.Item3.Send(14);

            l.Unlisten();

            CollectionAssert.AreEqual(new[] { 1, 2, 13, 14 }, output);
        }
示例#2
0
        public void SwitchCCatchFirst()
        {
            List <int> output = new List <int>();

            ValueTuple <DiscreteCell <int>, DiscreteCellSink <int>, DiscreteCellSink <int>, DiscreteCellSink <DiscreteCell <int> >, IListener> t = Transaction.Run(() =>
            {
                DiscreteCellSink <int> c1 = DiscreteCell.CreateSink(1);
                DiscreteCellSink <int> c2 = DiscreteCell.CreateSink(11);
                DiscreteCellSink <DiscreteCell <int> > s = DiscreteCell.CreateSink(c1.AsDiscreteCell());
                DiscreteCell <int> c = s.SwitchC();

                c1.Send(2);
                c2.Send(12);
                s.Send(c2);

                IListener l = c.Listen(output.Add);

                return(ValueTuple.Create(c, c1, c2, s, l));
            });

            t.Item2.Send(3);
            t.Item3.Send(13);

            Transaction.RunVoid(() =>
            {
                t.Item2.Send(4);
                t.Item3.Send(14);
                t.Item4.Send(t.Item2);
            });

            t.Item2.Send(5);
            t.Item3.Send(15);

            t.Item5.Unlisten();

            CollectionAssert.AreEqual(new[] { 12, 13, 4, 5 }, output);
        }