Ejemplo n.º 1
0
        public void SwitchEarlySOnCellLoop()
        {
            ValueTuple <Stream <int>, StreamSink <int>, StreamSink <int>, CellSink <Stream <int> > > t = Transaction.Run(() =>
            {
                CellLoop <Stream <int> > loop = Cell.CreateLoop <Stream <int> >();
                StreamSink <int> c1           = Stream.CreateSink <int>();
                StreamSink <int> c2           = Stream.CreateSink <int>();
                Stream <int> c             = loop.SwitchEarlyS();
                CellSink <Stream <int> > s = Cell.CreateSink(c1.AsStream());
                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[] { 2, 13, 14 }, output);
        }
Ejemplo n.º 2
0
        public void SwitchEarlySCatchFirst()
        {
            List <int> output = new List <int>();

            ValueTuple <Stream <int>, StreamSink <int>, StreamSink <int>, CellSink <Stream <int> >, IListener> t = Transaction.Run(() =>
            {
                StreamSink <int> c1        = Stream.CreateSink <int>();
                StreamSink <int> c2        = Stream.CreateSink <int>();
                CellSink <Stream <int> > s = Cell.CreateSink(c1.AsStream());
                Stream <int> c             = s.SwitchEarlyS();

                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);
        }