Beispiel #1
0
        public void Drain()
        {
            if (!bp.Enter())
            {
                return;
            }

            ISubscriber <R> a = actual;

            PublisherZipInner <T>[] inners = subscribers;

            int missed = 1;

            for (;;)
            {
                long r = bp.Requested();
                long e = 0L;

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

                    Exception ex = Volatile.Read(ref error);
                    if (ex != null)
                    {
                        Cancel();

                        ExceptionHelper.Terminate(ref error, out ex);

                        a.OnError(ex);

                        return;
                    }

                    int len = inners.Length;

                    T[]  values = new T[len];
                    bool full   = true;

                    for (int i = 0; i < len; i++)
                    {
                        PublisherZipInner <T> inner = inners[i];
                        bool d1 = inner.IsDone();

                        T    t;
                        bool empty1 = !inner.Peek(out t);
                        if (d1 && empty1)
                        {
                            Cancel();

                            a.OnComplete();

                            return;
                        }

                        if (empty1)
                        {
                            full = false;
                            break;
                        }

                        values[i] = t;
                    }

                    if (full)
                    {
                        if (r != e)
                        {
                            R v;
                            try
                            {
                                v = zipper(values);
                            }
                            catch (Exception ex1)
                            {
                                Cancel();

                                ExceptionHelper.Add(ref error, ex1);
                                ExceptionHelper.Terminate(ref error, out ex1);

                                a.OnError(ex1);
                                return;
                            }

                            a.OnNext(v);

                            foreach (PublisherZipInner <T> inner in inners)
                            {
                                inner.Drop();
                            }

                            e++;
                        }
                        else
                        {
                            if (e != 0)
                            {
                                bp.Produced(e);

                                foreach (PublisherZipInner <T> inner in inners)
                                {
                                    inner.Request(e);
                                }
                            }
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                missed = bp.Leave(missed);
                if (missed == 0)
                {
                    break;
                }
            }
        }
Beispiel #2
0
        public void Drain()
        {
            if (!bp.Enter())
            {
                return;
            }

            ISubscriber <R> a = actual;

            int missed = 1;

            for (;;)
            {
                long r = bp.Requested();
                long e = 0L;

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

                    Exception ex = Volatile.Read(ref error);
                    if (ex != null)
                    {
                        Cancel();

                        ExceptionHelper.Terminate(ref error, out ex);

                        a.OnError(ex);

                        return;
                    }

                    bool d1 = inner1.IsDone();
                    T1   t1;
                    bool e1 = !inner1.Peek(out t1);

                    if (d1 && e1)
                    {
                        Cancel();

                        a.OnComplete();

                        return;
                    }

                    bool d2 = inner2.IsDone();
                    T2   t2;
                    bool e2 = !inner2.Peek(out t2);

                    if (d2 && e2)
                    {
                        Cancel();

                        a.OnComplete();

                        return;
                    }

                    if (!e1 && !e2)
                    {
                        if (r != e)
                        {
                            R v;
                            try
                            {
                                v = zipper(t1, t2);
                            }
                            catch (Exception ex1)
                            {
                                Cancel();

                                ExceptionHelper.Add(ref error, ex1);
                                ExceptionHelper.Terminate(ref error, out ex1);

                                a.OnError(ex1);
                                return;
                            }

                            a.OnNext(v);

                            inner1.Drop();
                            inner2.Drop();

                            e++;
                        }
                        else
                        {
                            if (e != 0)
                            {
                                bp.Produced(e);

                                inner1.Request(e);
                                inner2.Request(e);
                            }
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

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