Exemple #1
0
        /// <inheritdoc/>
        public void OnNext(T t)
        {
            if (establishedFusionMode == FuseableHelper.ASYNC)
            {
                try
                {
                    T v;
                    while (qs.Poll(out v))
                    {
                        values.Add(v);
                    }
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
                Volatile.Write(ref valueCount, values.Count);
                Volatile.Write(ref lastTimestamp, DateTimeOffset.UtcNow.UtcMillis());
                return;
            }

            if (!subscriptionValidated)
            {
                subscriptionValidated = true;
                if (s == null)
                {
                    errors.Add(new InvalidOperationException("OnSubscribe was not called before OnNext(" + t + ")"));
                }
            }

            values.Add(t);
            Volatile.Write(ref valueCount, valueCount + 1);
            Volatile.Write(ref lastTimestamp, DateTimeOffset.UtcNow.UtcMillis());
        }
Exemple #2
0
        /// <inheritdoc/>
        public void OnSubscribe(ISubscription s)
        {
            subscriptions++;
            if (SubscriptionHelper.SetOnce(ref this.s, s))
            {
                var qs = s as IQueueSubscription <T>;
                this.qs = qs;
                if (qs != null)
                {
                    if (requestFusionMode != FuseableHelper.NONE)
                    {
                        int m = qs.RequestFusion(requestFusionMode);
                        establishedFusionMode = m;
                        if (m == FuseableHelper.SYNC)
                        {
                            try
                            {
                                try
                                {
                                    T v;

                                    while (qs.Poll(out v))
                                    {
                                        values.Add(v);
                                    }
                                    completions++;
                                    Volatile.Write(ref valueCount, values.Count);
                                    Volatile.Write(ref lastTimestamp, DateTimeOffset.UtcNow.UtcMillis());
                                }
                                catch (Exception ex)
                                {
                                    errors.Add(ex);
                                }
                            }
                            finally
                            {
                                cde.Signal();
                            }

                            return;
                        }
                    }
                }

                long r = Interlocked.Exchange(ref requested, 0L);
                if (r != 0L)
                {
                    s.Request(r);
                }
            }
        }