Ejemplo n.º 1
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (maxConcurrency == int.MaxValue)
            {
                var parent = new SingleConcatEagerAllCoordinator <T>(observer, delayErrors);

                foreach (var src in sources)
                {
                    if (!parent.SubscribeTo(src))
                    {
                        break;
                    }
                }

                parent.Done();

                return(parent);
            }
            else
            {
                var parent = new ConcatEagerLimitedCoordinator(observer, sources, maxConcurrency, delayErrors);

                parent.Drain();

                return(parent);
            }
        }
        public IDisposable Subscribe(IObserver <T> observer)
        {
            var en = default(IEnumerator <ISingleSource <T> >);

            try
            {
                en = RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator");
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
                return(DisposableHelper.EMPTY);
            }

            if (maxConcurrency == int.MaxValue)
            {
                var parent = new SingleConcatEagerAllCoordinator <T>(observer, delayErrors);

                for (; ;)
                {
                    var b   = false;
                    var src = default(ISingleSource <T>);
                    try
                    {
                        b = en.MoveNext();
                        if (!b)
                        {
                            break;
                        }
                        src = en.Current;
                    }
                    catch (Exception ex)
                    {
                        parent.SubscribeTo(SingleSource.Error <T>(ex));
                        break;
                    }

                    if (!parent.SubscribeTo(src))
                    {
                        break;
                    }
                }

                en.Dispose();

                parent.Done();

                return(parent);
            }
            else
            {
                var parent = new ConcatEagerLimitedCoordinator(observer, en, maxConcurrency, delayErrors);

                parent.Drain();

                return(parent);
            }
        }