示例#1
0
 public void Cancel()
 {
     if (!Volatile.Read(ref cancelled))
     {
         Volatile.Write(ref cancelled, true);
         upstream.Cancel();
         worker.Dispose();
         if (!outputMode && Interlocked.Increment(ref wip) == 1)
         {
             queue.Clear();
         }
     }
 }
示例#2
0
 public void Cancel()
 {
     Volatile.Write(ref cancelled, true);
     DisposableHelper.Dispose(ref upstream);
     if (Interlocked.Increment(ref wip) == 1)
     {
         queue.Clear();
     }
 }
示例#3
0
        internal static void QueueDrainFused <T>(IFlowableSubscriber <T> a,
                                                 ref int wip, ISimpleQueue <T> q, ref bool cancelled, ref bool done, ref Exception error)
        {
            if (Interlocked.Increment(ref wip) != 1)
            {
                return;
            }

            int missed = 1;

            for (;;)
            {
                if (Volatile.Read(ref cancelled))
                {
                    q.Clear();
                    return;
                }
                bool d     = Volatile.Read(ref done);
                bool empty = q.IsEmpty();

                if (!empty)
                {
                    a.OnNext(default(T));
                }

                if (d)
                {
                    var ex = error;
                    if (ex == null)
                    {
                        a.OnComplete();
                    }
                    else
                    {
                        a.OnError(ex);
                    }
                }

                int w = Volatile.Read(ref wip);
                if (w == missed)
                {
                    missed = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
                else
                {
                    missed = w;
                }
            }
        }
示例#4
0
            void DrainFused()
            {
                int missed = 1;

                IFlowableSubscriber <T> a = actual;
                ISimpleQueue <T>        q = queue;

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

                    bool d     = Volatile.Read(ref done);
                    bool empty = q.IsEmpty();

                    if (!empty)
                    {
                        a.OnNext(default(T));
                    }

                    if (d)
                    {
                        Exception ex = error;
                        if (ex != null)
                        {
                            a.OnError(ex);
                        }
                        else
                        {
                            a.OnComplete();
                        }
                        return;
                    }

                    int w = Volatile.Read(ref wip);
                    if (w == missed)
                    {
                        missed = Interlocked.Add(ref wip, -missed);
                        if (missed == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        missed = w;
                    }
                }
            }
 public void Clear()
 {
     queue.Clear();
 }
示例#6
0
 public void Clear()
 {
     queue.Clear();
     accumulator = default(R);
 }
 public void Clear()
 {
     windows.Clear();
 }
示例#8
0
 public void Clear()
 {
     queue.Clear();
     DisposeSilently(current);
     current = null;
 }
示例#9
0
            void DrainAsync()
            {
                int  missed = 1;
                long e      = emitted;
                int  f      = consumed;
                int  lim    = limit;
                IFlowableSubscriber <T> a = actual;
                ISimpleQueue <T>        q = queue;

                for (;;)
                {
                    long r = Volatile.Read(ref requested);

                    while (e != r)
                    {
                        if (Volatile.Read(ref cancelled))
                        {
                            q.Clear();
                            return;
                        }

                        bool d     = Volatile.Read(ref done);
                        bool empty = !q.Poll(out T item);

                        if (d && empty)
                        {
                            Exception ex = error;
                            if (ex != null)
                            {
                                a.OnError(ex);
                            }
                            else
                            {
                                a.OnComplete();
                            }
                            return;
                        }

                        if (empty)
                        {
                            break;
                        }

                        a.OnNext(item);

                        e++;

                        if (++f == lim)
                        {
                            f = 0;
                            upstream.Request(lim);
                        }
                    }

                    if (e == r)
                    {
                        if (Volatile.Read(ref cancelled))
                        {
                            q.Clear();
                            return;
                        }

                        bool d     = Volatile.Read(ref done);
                        bool empty = q.IsEmpty();

                        if (d && empty)
                        {
                            Exception ex = error;
                            if (ex != null)
                            {
                                a.OnError(ex);
                            }
                            else
                            {
                                a.OnComplete();
                            }
                            return;
                        }
                    }

                    int w = Volatile.Read(ref wip);
                    if (w == missed)
                    {
                        emitted  = e;
                        consumed = f;
                        missed   = Interlocked.Add(ref wip, -missed);
                        if (missed == 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        missed = w;
                    }
                }
            }
示例#10
0
        internal static void QueueDrain <T>(IFlowableSubscriber <T> a,
                                            ref int wip, ISimpleQueue <T> q,
                                            ref long requested, ref long emitted, ref bool cancelled, ref bool done, ref Exception error)
        {
            if (Interlocked.Increment(ref wip) != 1)
            {
                return;
            }

            int missed = 1;
            var e      = emitted;

            for (;;)
            {
                long r = Volatile.Read(ref requested);

                while (e != r)
                {
                    if (Volatile.Read(ref cancelled))
                    {
                        q.Clear();
                        return;
                    }

                    bool d     = Volatile.Read(ref done);
                    bool empty = !q.Poll(out var item);

                    if (d && empty)
                    {
                        var ex = error;
                        if (ex == null)
                        {
                            a.OnComplete();
                        }
                        else
                        {
                            a.OnError(ex);
                        }
                        return;
                    }

                    if (empty)
                    {
                        break;
                    }

                    a.OnNext(item);

                    e++;
                }

                if (e == r)
                {
                    if (Volatile.Read(ref cancelled))
                    {
                        q.Clear();
                        return;
                    }

                    bool d     = Volatile.Read(ref done);
                    bool empty = q.IsEmpty();

                    if (d && empty)
                    {
                        var ex = error;
                        if (ex == null)
                        {
                            a.OnComplete();
                        }
                        else
                        {
                            a.OnError(ex);
                        }
                        return;
                    }
                }

                int w = Volatile.Read(ref wip);
                if (w == missed)
                {
                    emitted = e;
                    missed  = Interlocked.Add(ref wip, -missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
                else
                {
                    missed = w;
                }
            }
        }