Пример #1
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            if (maxConcurrency == int.MaxValue)
            {
                var parent = new MergeMaxCoordinator(observer, delayErrors);
                observer.OnSubscribe(parent);

                foreach (var source in sources)
                {
                    if (source == null)
                    {
                        parent.Error(new NullReferenceException());
                        return;
                    }
                    if (!parent.SubscribeTo(source))
                    {
                        return;
                    }
                }

                parent.SetDone();
            }
            else
            {
                var parent = new MergeLimitedCoordinator(observer, delayErrors, maxConcurrency, sources);
                observer.OnSubscribe(parent);

                parent.Drain();
            }
        }
Пример #2
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            if (maxConcurrency == int.MaxValue)
            {
                var en = default(IEnumerator <IObservableSource <T> >);
                try
                {
                    en = RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator");
                }
                catch (Exception ex)
                {
                    DisposableHelper.Error(observer, ex);
                    return;
                }

                var parent = new MergeMaxCoordinator(observer, delayErrors);
                observer.OnSubscribe(parent);

                for (; ;)
                {
                    var b   = false;
                    var src = default(IObservableSource <T>);

                    try
                    {
                        b = en.MoveNext();
                        if (b)
                        {
                            src = RequireNonNullRef(en.Current, "The enumerator returned a null IObservableSource");
                        }
                    }
                    catch (Exception ex)
                    {
                        parent.Error(ex);
                        en.Dispose();
                        return;
                    }

                    if (b)
                    {
                        if (!parent.SubscribeTo(src))
                        {
                            en.Dispose();
                            break;
                        }
                    }
                    else
                    {
                        en.Dispose();
                        break;
                    }
                }

                parent.SetDone();
            }
            else
            {
                var en = default(IEnumerator <IObservableSource <T> >);
                try
                {
                    en = RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator");
                }
                catch (Exception ex)
                {
                    DisposableHelper.Error(observer, ex);
                    return;
                }

                var parent = new MergeLimitedCoordinator(observer, delayErrors, maxConcurrency, en);
                observer.OnSubscribe(parent);

                parent.Drain();
            }
        }