Exemplo n.º 1
0
        internal static Behavior <T> SwitchBImpl <T, T2>(this Behavior <T2> bba)
            where T2 : Behavior <T>
        {
            return(TransactionInternal.Apply(
                       (trans1, _) =>
            {
                Lazy <T> za = bba.SampleLazyImpl().MapImpl(ba => ba.SampleImpl());
                Stream <T> @out = new Stream <T>(bba.KeepListenersAlive);
                MutableListener currentListener = new MutableListener();

                void H(TransactionInternal trans2, Behavior <T> ba)
                {
                    IListener cl = currentListener;
                    cl.Unlisten();

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

                IListener l1 = bba.Value(trans1).Listen(@out.Node, trans1, H, false);
                return @out.UnsafeAttachListener(l1)
                .UnsafeAttachListener(currentListener)
                .HoldLazyInternal(trans1, za);
            },
                       false));
        }
Exemplo n.º 2
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.º 3
0
 public static void SetListener(this MutableListener m, IListener listener) => m.SetListenerImpl(listener);
Exemplo n.º 4
0
        public static IListenerWithWeakReference GetListenerWithWeakReference(this MutableListener m)
        {
            IListener l = m;

            return(l.GetListenerWithWeakReference());
        }
Exemplo n.º 5
0
        public static void Unlisten(this MutableListener m)
        {
            IListener l = m;

            l.Unlisten();
        }
Exemplo n.º 6
0
 public static void ClearListener(this MutableListener m) => m.ClearListenerImpl();