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