示例#1
0
 public PublisherCacheInner(ISubscriber <T> actual, PublisherCache <T> parent, int bufferSize, PublisherCacheItem h)
 {
     this.actual     = actual;
     this.parent     = parent;
     this.bufferSize = bufferSize;
     this.current    = h;
 }
示例#2
0
            bool CheckTerminated(bool d, bool empty, ISubscriber <T> a, PublisherCache <T> p)
            {
                if (d && empty)
                {
                    Exception ex = p.Error();
                    if (ex != null)
                    {
                        a.OnError(ex);
                    }
                    else
                    {
                        a.OnComplete();
                    }

                    return(true);
                }
                return(false);
            }
示例#3
0
            internal void Drain()
            {
                if (!bp.Enter())
                {
                    return;
                }

                PublisherCache <T> p    = parent;
                ISubscriber <T>    a    = actual;
                PublisherCacheItem item = current;
                int c = offset;

                int  missed = 1;
                long r      = bp.Requested();
                long e      = 0L;

                for (;;)
                {
                    if (IsCancelled())
                    {
                        return;
                    }

                    if (CheckTerminated(p.IsDone(), item.lvCount() == c && item.lvNext() == null, a, p))
                    {
                        return;
                    }

                    while (r != e)
                    {
                        if (IsCancelled())
                        {
                            return;
                        }
                        bool d     = p.IsDone();
                        var  next  = item.lvNext();
                        var  f     = item.lvCount();
                        bool empty = f == c && next == null;

                        if (CheckTerminated(d, empty, a, p))
                        {
                            return;
                        }

                        if (empty)
                        {
                            break;
                        }

                        if (f == c)
                        {
                            item = next;
                            c    = 0;
                        }

                        T v = item.array[c];

                        c++;
                    }

                    if (CheckTerminated(p.IsDone(), item.lvCount() == c && item.lvNext() == null, a, p))
                    {
                        return;
                    }

                    r = bp.Requested();

                    if (e == r)
                    {
                        current = item;
                        offset  = c;
                        r       = bp.Produced(e);
                        if (r != 0L)
                        {
                            e = 0L;
                            continue;
                        }
                    }

                    missed = bp.Leave(missed);
                    if (missed == 0)
                    {
                        break;
                    }
                }
            }