Exemple #1
0
 /// <summary>
 ///     Resolve the loop to specify what the <see cref="CellLoop{T}" /> was a forward reference to.  This method
 ///     must be called inside the same transaction as the one in which this <see cref="CellLoop{T}" /> instance was
 ///     created and used.
 ///     This requires an explicit transaction to be created with <see cref="Transaction.Run{T}(Func{T})" /> or
 ///     <see cref="Transaction.RunVoid(Action)" />.
 /// </summary>
 /// <param name="c">The cell that was forward referenced.</param>
 public void Loop(Cell <T> c)
 {
     Transaction.Apply(trans =>
     {
         this.streamLoop.Loop(c.Updates(trans));
         this.LazyInitialValue = c.SampleLazy(trans);
         return(Unit.Value);
     }, false);
 }
        /// <summary>
        ///     Unwrap a cell inside another cell to give a time-varying cell implementation.
        /// </summary>
        /// <typeparam name="T">The type of the cell.</typeparam>
        /// <param name="cca">The cell containing another cell.</param>
        /// <returns>The unwrapped cell.</returns>
        public static Cell <T> SwitchC <T>(this Cell <Cell <T> > cca)
        {
            return(Transaction.Apply(trans1 =>
            {
                Lazy <T> za = cca.SampleLazy().Map(ca => ca.Sample());
                Stream <T> @out = new Stream <T>(cca.KeepListenersAlive);
                MutableListener currentListener = new MutableListener();
                Action <Transaction, Cell <T> > h = (trans2, ca) =>
                {
                    currentListener.Unlisten();

                    currentListener.SetListener(ca.Value(trans2).Listen(@out.Node, trans2, @out.Send, false));
                };
                IListener l1 = cca.Value(trans1).Listen(@out.Node, trans1, h, false);
                return @out.UnsafeAttachListener(l1).UnsafeAttachListener(currentListener).HoldLazyInternal(za);
            }, false));
        }
Exemple #3
0
        /// <summary>
        ///     Unwrap a cell inside another cell to give a time-varying cell implementation.
        /// </summary>
        /// <typeparam name="T">The type of the cell.</typeparam>
        /// <param name="cca">The cell containing another cell.</param>
        /// <returns>The unwrapped cell.</returns>
        public static Cell <T> SwitchC <T>(this Cell <Cell <T> > cca)
        {
            return(Transaction.Apply(trans1 =>
            {
                Lazy <T> za = cca.SampleLazy().Map(ca => ca.Sample());
                Stream <T> @out = new Stream <T>();
                IListener currentListener = null;
                Action <Transaction, Cell <T> > h = (trans2, ca) =>
                {
                    using (currentListener)
                    {
                    }

                    currentListener = ca.Value(trans2).Listen(@out.Node, trans2, (trans3, a) => @out.Send(trans3, a), false);
                };
                IListener l1 = cca.Value(trans1).Listen(@out.Node, trans1, h, false);
                return @out.UnsafeAddCleanup(l1).HoldLazy(za);
            }));
        }