Exemple #1
0
        public bool MoveNext()
        {
            if (SubscriptionHelper.IsCancelled(ref upstream))
            {
                return(false);
            }
            if (Volatile.Read(ref wip) == 0)
            {
                Monitor.Enter(this);
                try
                {
                    for (;;)
                    {
                        if (SubscriptionHelper.IsCancelled(ref upstream))
                        {
                            return(false);
                        }

                        if (Volatile.Read(ref wip) != 0)
                        {
                            break;
                        }
                        Monitor.Wait(this);
                    }
                }
                finally
                {
                    Monitor.Exit(this);
                }
            }
            if (queue.Poll(out current))
            {
                int c = consumed + 1;
                if (c == limit)
                {
                    consumed = 0;
                    upstream.Request(c);
                }
                else
                {
                    consumed = c;
                }
                Interlocked.Decrement(ref wip);
                return(true);
            }
            var ex = error;

            if (ex != null)
            {
                throw ex;
            }
            return(false);
        }
 public bool Poll(out T item)
 {
     return(queue.Poll(out item));
 }