コード例 #1
0
            public void InnerNext(CombineLatestSubscriber sender, int index, T value)
            {
                var a = latest;
                int n = a.Length;

                int activeCount = Volatile.Read(ref active);

                if (!sender.hasValue)
                {
                    sender.hasValue = true;
                    activeCount     = Interlocked.Increment(ref active);
                }

                bool drain = activeCount == n;

                lock (this) {
                    a[index] = value;

                    if (drain)
                    {
                        T[] b = new T[n];
                        Array.Copy(a, 0, b, 0, n);
                        queue.Offer(new Entry(b, sender));
                    }
                }

                if (drain)
                {
                    Drain();
                }
                else
                {
                    sender.RequestOne();
                }
            }
コード例 #2
0
            void InnerNext(CombineLatestSubscriber sender, T item)
            {
                bool drain = false;

                lock (this)
                {
                    if (!sender.hasValue)
                    {
                        active++;
                        sender.hasValue = true;
                    }

                    latest[sender.index] = item;

                    int n = subscribers.Length;
                    drain = active == n;
                    if (drain)
                    {
                        Entry e = new Entry();
                        e.sender = sender;
                        e.items  = new T[n];
                        Array.Copy(latest, 0, e.items, 0, n);
                        queue.Offer(e);
                    }
                }

                if (drain)
                {
                    Drain();
                }
                else
                {
                    sender.RequestOne();
                }
            }