コード例 #1
0
ファイル: Stream.cs プロジェクト: thalesians/sodium
        internal IWeakListener Listen(
            Node target,
            TransactionInternal trans,
            Action <TransactionInternal, T> action,
            bool suppressEarlierFirings)
        {
            (bool changed, Node <T> .Target nodeTarget) = this.Node.Link(trans, action, target);
            if (changed)
            {
                trans.SetNeedsRegenerating();
            }

            // ReSharper disable once LocalVariableHidesMember
            List <T> firings = this.firings.ToList();

            if (!suppressEarlierFirings && firings.Count > 0)
            {
                trans.Prioritized(
                    target,
                    trans2 =>
                {
                    // Anything sent already in this transaction must be sent now so that
                    // there's no order dependency between send and listen.
                    foreach (T a in firings)
                    {
                        TransactionInternal.InCallback++;
                        try
                        {
                            // Don't allow transactions to interfere with Sodium
                            // internals.
                            action(trans2, a);
                        }
                        finally
                        {
                            TransactionInternal.InCallback--;
                        }
                    }
                });
            }

            return(new ListenerImplementation(this, action, nodeTarget));
        }