コード例 #1
0
        public void OnNext(T t)
        {
            if (doneOverflow)
            {
                return;
            }

            if (!q.Offer(t))
            {
                doneOverflow = true;

                s.Cancel();

                Exception e = BackpressureHelper.MissingBackpressureException();

                try
                {
                    onOverflow?.Invoke();
                }
                catch (Exception ex)
                {
                    e = new AggregateException(e, ex);
                }

                error = e;
                Volatile.Write(ref done, true);
            }
            Drain();
        }
コード例 #2
0
 public void OnNext(T t)
 {
     if (!queue.Offer(t))
     {
         s.Cancel();
         OnError(BackpressureHelper.MissingBackpressureException());
         return;
     }
     Schedule();
 }
コード例 #3
0
 public void OnNext(T t)
 {
     if (!queue.Offer(t))
     {
         Cancel();
         OnError(BackpressureHelper.MissingBackpressureException("Queue full?!"));
         return;
     }
     Drain();
 }
コード例 #4
0
 public void OnNext(T t)
 {
     if (!q.Offer(t))
     {
         OnError(BackpressureHelper.MissingBackpressureException());
     }
     else
     {
         parent.Drain();
     }
 }
 public override void OnNext(T t)
 {
     if (fusionMode != FuseableHelper.ASYNC)
     {
         if (!queue.Offer(t))
         {
             OnError(BackpressureHelper.MissingBackpressureException());
             return;
         }
     }
     Drain();
 }
コード例 #6
0
 public void OnNext(IOrderedItem <T> t)
 {
     if (fusionMode == FuseableHelper.NONE)
     {
         if (!queue.Offer(t))
         {
             OnError(BackpressureHelper.MissingBackpressureException("Queue full?!"));
             return;
         }
     }
     parent.Drain();
 }
コード例 #7
0
            internal void Enqueue(R value)
            {
                if (q.array == null)
                {
                    q.InitVolatile(parent.bufferSize);
                }

                if (!q.Offer(value))
                {
                    OnError(BackpressureHelper.MissingBackpressureException());
                }
            }
コード例 #8
0
 public void OnNext(T t)
 {
     if (sourceMode == FuseableHelper.NONE)
     {
         if (!queue.Offer(t))
         {
             s.Cancel();
             OnError(BackpressureHelper.MissingBackpressureException("Queue is full?!"));
             return;
         }
     }
     Schedule();
 }
コード例 #9
0
        internal void Run()
        {
            if (Volatile.Read(ref requested) != 0L)
            {
                actual.OnNext(counter++);

                BackpressureHelper.Produced(ref requested, 1);
            }
            else
            {
                actual.OnError(BackpressureHelper.MissingBackpressureException());
            }
        }
コード例 #10
0
            public void OnNext(T t)
            {
                if (!q.Offer(t))
                {
                    arbiter.Cancel();

                    OnError(BackpressureHelper.MissingBackpressureException());
                }
                else
                {
                    Drain();
                }
            }
コード例 #11
0
            internal void InnerNext(JoinInnerSubscriber inner, T value)
            {
                if (QueueDrainHelper.TryEnter(ref wip))
                {
                    long r = Volatile.Read(ref requested);
                    if (r != 0L)
                    {
                        actual.OnNext(value);
                        if (r != long.MaxValue)
                        {
                            Interlocked.Decrement(ref requested);
                        }
                        inner.RequestOne();
                    }
                    else
                    {
                        var q = inner.Queue();

                        if (!q.Offer(value))
                        {
                            InnerError(BackpressureHelper.MissingBackpressureException("Queue full?!"));
                            return;
                        }
                    }

                    if (QueueDrainHelper.Leave(ref wip, 1) == 0)
                    {
                        return;
                    }
                }
                else
                {
                    var q = inner.Queue();

                    if (!q.Offer(value))
                    {
                        InnerError(BackpressureHelper.MissingBackpressureException("Queue full?!"));
                        return;
                    }

                    if (!QueueDrainHelper.Enter(ref wip))
                    {
                        return;
                    }
                }

                DrainLoop();
            }
コード例 #12
0
 internal void Run()
 {
     if (Volatile.Read(ref requested))
     {
         available = true;
         actual.OnNext(0);
         if (!DisposableHelper.IsDisposed(ref d))
         {
             actual.OnComplete();
         }
     }
     else
     {
         actual.OnError(BackpressureHelper.MissingBackpressureException());
     }
 }
コード例 #13
0
            internal void OnNext(T value)
            {
                long r = Volatile.Read(ref requested);
                long p = produced;

                if (r != p)
                {
                    produced = p + 1;
                    actual.OnNext(value);
                }
                else
                {
                    Cancel();
                    actual.OnError(BackpressureHelper.MissingBackpressureException());
                }
            }
コード例 #14
0
        /// <inheritDoc/>
        public void OnNext(T t)
        {
            if (done)
            {
                return;
            }

            if (sourceMode == FuseableHelper.NONE)
            {
                if (!queue.Offer(t))
                {
                    SubscriptionHelper.Cancel(ref s);
                    OnError(BackpressureHelper.MissingBackpressureException());
                    return;
                }
            }
            Drain();
        }
コード例 #15
0
            public void OnNext(T t)
            {
                if (done)
                {
                    return;
                }

                if (sourceMode != FuseableHelper.ASYNC)
                {
                    if (!queue.Offer(t))
                    {
                        s.Cancel();
                        OnError(BackpressureHelper.MissingBackpressureException());
                        return;
                    }
                }

                Signal();
            }
コード例 #16
0
        void Emit(IProcessor <T, T> w)
        {
            long r = bp.Requested();

            if (r != 0L)
            {
                actual.OnNext(w);
                if (r != long.MaxValue)
                {
                    bp.Produced(1);
                }
            }
            else
            {
                Cancel();

                OnError(BackpressureHelper.MissingBackpressureException());
            }
        }
コード例 #17
0
        void Emit(IProcessor <T, T> w)
        {
            long r = Volatile.Read(ref requested);

            if (r != 0L)
            {
                actual.OnNext(w);
                if (r != long.MaxValue)
                {
                    Interlocked.Decrement(ref requested);
                }
            }
            else
            {
                Cancel();

                actual.OnError(BackpressureHelper.MissingBackpressureException());
            }
        }
コード例 #18
0
        void Emit(T value, long index)
        {
            if (index == Volatile.Read(ref this.index))
            {
                long r = bp.Requested();
                if (r != 0L)
                {
                    actual.OnNext(value);

                    if (r != long.MaxValue)
                    {
                        bp.Produced(1);
                    }
                    return;
                }

                Cancel();

                actual.OnError(BackpressureHelper.MissingBackpressureException());
            }
        }
コード例 #19
0
        internal void Run()
        {
            long c = count;

            count = c + 1;

            long r = Volatile.Read(ref requested);

            if (r != 0L)
            {
                actual.OnNext(c);

                if (r != long.MaxValue)
                {
                    Interlocked.Decrement(ref requested);
                }
                return;
            }
            Cancel();

            actual.OnError(BackpressureHelper.MissingBackpressureException());
        }
コード例 #20
0
            public void Next(T value)
            {
                if (done)
                {
                    return;
                }

                long r = Volatile.Read(ref requested);
                long p = produced;

                if (r != p)
                {
                    produced = p + 1;
                    actual.OnNext(value);
                }
                else
                {
                    done = true;
                    Cancel();
                    actual.OnError(BackpressureHelper.MissingBackpressureException());
                }
            }
コード例 #21
0
        public void OnNext(T t)
        {
            if (done)
            {
                return;
            }

            long e = produced.Get();
            long r = requested.GetVolatile();

            if (r != e)
            {
                produced.Set(e + 1);

                actual.OnNext(t);
            }
            else
            {
                done = true;
                s.Cancel();

                actual.OnError(BackpressureHelper.MissingBackpressureException());
            }
        }
コード例 #22
0
        internal void Run()
        {
            var v = Interlocked.Exchange(ref value, null);

            if (v != null)
            {
                long r = Volatile.Read(ref requested);

                if (r != 0L)
                {
                    actual.OnNext(v.value);
                    if (r != long.MaxValue)
                    {
                        Interlocked.Decrement(ref requested);
                    }
                }
                else
                {
                    Cancel();

                    actual.OnError(BackpressureHelper.MissingBackpressureException());
                }
            }
        }
コード例 #23
0
            void Drain()
            {
                if (!QueueDrainHelper.Enter(ref wip))
                {
                    return;
                }

                int missed = 1;
                var q      = queue;
                var a      = actual;
                var buf    = buffer;

                for (;;)
                {
                    for (;;)
                    {
                        if (Volatile.Read(ref cancelled))
                        {
                            q.Clear();
                            return;
                        }

                        Exception ex = Volatile.Read(ref error);
                        if (ex != null)
                        {
                            q.Clear();
                            a.OnError(ex);
                            return;
                        }

                        BufferWork bw;

                        if (q.Poll(out bw))
                        {
                            switch (bw.type)
                            {
                            case BufferWorkType.COMPLETE:
                            {
                                Interlocked.Exchange(ref index, long.MaxValue);

                                q.Clear();
                                buffer = null;

                                if (buf.Count == 0L)
                                {
                                    a.OnComplete();
                                }
                                else
                                {
                                    long r = Volatile.Read(ref requested);
                                    long p = produced;
                                    if (r != p)
                                    {
                                        a.OnNext(buf);
                                        a.OnComplete();
                                    }
                                    else
                                    {
                                        a.OnError(BackpressureHelper.MissingBackpressureException());
                                    }
                                }

                                worker.Dispose();
                                return;
                            }

                            case BufferWorkType.BOUNDARY:
                            {
                                long idx = Interlocked.Increment(ref index);
                                if (buf.Count != 0)
                                {
                                    long r = Volatile.Read(ref requested);
                                    long p = produced;
                                    if (r != p)
                                    {
                                        buffer = new List <T>();
                                        a.OnNext(buf);
                                        buf = buffer;

                                        if (r != long.MaxValue)
                                        {
                                            produced = p + 1;
                                        }
                                        Schedule(idx);
                                    }
                                    else
                                    {
                                        s.Cancel();
                                        d.Dispose();
                                        worker.Dispose();

                                        q.Clear();

                                        a.OnError(BackpressureHelper.MissingBackpressureException());

                                        return;
                                    }
                                }
                                else
                                {
                                    Schedule(idx);
                                }
                            }
                            break;

                            default:
                            {
                                buf.Add(bw.value);
                                if (buf.Count == maxSize)
                                {
                                    long idx = Interlocked.Increment(ref index);
                                    long r   = Volatile.Read(ref requested);
                                    long p   = produced;
                                    if (r != p)
                                    {
                                        buffer = new List <T>();
                                        a.OnNext(buf);
                                        buf = buffer;

                                        if (r != long.MaxValue)
                                        {
                                            produced = p + 1;
                                        }
                                        Schedule(idx);
                                    }
                                    else
                                    {
                                        s.Cancel();
                                        d.Dispose();
                                        worker.Dispose();

                                        q.Clear();

                                        a.OnError(BackpressureHelper.MissingBackpressureException());

                                        return;
                                    }
                                }
                            }
                            break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    missed = QueueDrainHelper.Leave(ref wip, missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }