Exemplo n.º 1
0
        internal static Stream <T> SwitchSImpl <T, T2>(this Behavior <T2> bsa) where T2 : Stream <T>
        {
            return(TransactionInternal.Apply(
                       (trans1, _) =>
            {
                Stream <T> @out = new Stream <T>(bsa.KeepListenersAlive);
                MutableListener currentListener = new MutableListener();

                void HInitial(TransactionInternal trans2, Stream <T> sa)
                {
                    IListener cl = currentListener;
                    cl.Unlisten();

                    currentListener.SetListenerImpl(sa.Listen(@out.Node, trans2, @out.Send, false));
                }

                void H(TransactionInternal trans2, Stream <T> sa)
                {
                    trans2.Last(
                        () =>
                    {
                        IListener cl = currentListener;
                        cl.Unlisten();

                        currentListener.SetListenerImpl(sa.Listen(@out.Node, trans2, @out.Send, true));
                    });
                }

                trans1.Prioritized(new Node <T>(), trans2 => HInitial(trans2, bsa.SampleNoTransaction()));
                IListener l1 = bsa.Updates().Listen(new Node <T>(), trans1, H, false);
                return @out.UnsafeAttachListener(l1).UnsafeAttachListener(currentListener);
            },
                       false));
        }
Exemplo n.º 2
0
        internal Stream <TResult> SnapshotImpl <T1, T2, TResult>(Behavior <T1> b1, Behavior <T2> b2, Func <T, T1, T2, TResult> f)
        {
            Stream <TResult> @out = new Stream <TResult>(this.KeepListenersAlive);
            IListener        l    = this.Listen(
                @out.Node,
                (trans2, a) => @out.Send(trans2, f(a, b1.SampleNoTransaction(), b2.SampleNoTransaction())));

            return(@out.UnsafeAttachListener(l));
        }