Ejemplo n.º 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();
            }
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            if (serialize)
            {
                var parent = new CreateDisposableSerializedEmitter(observer);

                observer.OnSubscribe(parent);
                try
                {
                    onSubscribe(parent);
                }
                catch (Exception ex)
                {
                    parent.OnError(ex);
                }
            }
            else
            {
                var parent = new CreateDisposableEmitter(observer);
                observer.OnSubscribe(parent);
                try
                {
                    onSubscribe(parent);
                }
                catch (Exception ex)
                {
                    parent.OnError(ex);
                }
            }
        }
            public void OnSubscribe(IDisposable d)
            {
                upstream = d;
                if (d is IFuseableDisposable <T> f)
                {
                    var m = f.RequestFusion(FusionSupport.AnyBoundary);

                    if (m == FusionSupport.Sync)
                    {
                        sourceMode = m;
                        queue      = f;
                        Volatile.Write(ref done, true);
                        downstream.OnSubscribe(this);
                        Drain();
                        return;
                    }
                    if (m == FusionSupport.Async)
                    {
                        sourceMode = m;
                        queue      = f;
                        downstream.OnSubscribe(this);
                        return;
                    }
                }

                queue = new SpscLinkedArrayQueue <T>(capacityHint);
                downstream.OnSubscribe(this);
            }
Ejemplo n.º 4
0
            public void OnSubscribe(IDisposable d)
            {
                upstream = d;
                try
                {
                    onSubscribe?.Invoke(d);
                }
                catch (Exception ex)
                {
                    downstream.OnSubscribe(this);
                    OnError(ex);
                    return;
                }

                downstream.OnSubscribe(this);
            }
Ejemplo n.º 5
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new RepeatPredicteObserver(observer, source, predicate);

            observer.OnSubscribe(parent);
            parent.Next();
        }
        /// <summary>
        /// Subscribes the first observer to this subject and
        /// starts replaying/relaying signals. All future
        /// observers receive an InvalidOperationException.
        /// </summary>
        /// <param name="observer">The observer to subscribe with.</param>
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNullRef(observer, nameof(observer));

            if (Interlocked.CompareExchange(ref once, 1, 0) == 0)
            {
                var inner = new MonocastDisposable(observer, this);
                observer.OnSubscribe(inner);
                if (Interlocked.CompareExchange(ref this.observer, inner, null) == null)
                {
                    if (inner.IsDisposed())
                    {
                        this.observer = null;
                    }
                    else
                    {
                        Drain();
                    }
                }
            }
            else
            {
                DisposableHelper.Error(observer, new InvalidOperationException("MonocastSubject allows at most one observer"));
            }
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNull(observer, nameof(observer));

            var errorSignals = new PublishSubject <Exception>();
            var redo         = default(IObservableSource <U>);

            try
            {
                redo = ValidationHelper.RequireNonNullRef(handler(errorSignals), "The handler returned a null IObservableSource");
            }
            catch (Exception ex)
            {
                DisposableHelper.Error(observer, ex);
                return;
            }

            var parent = new MainObserver(observer, source, new SerializedSignalObserver <Exception>(errorSignals));

            observer.OnSubscribe(parent);

            redo.Subscribe(parent.handlerObserver);

            parent.HandlerNext();
        }
 public override void OnSubscribe(IDisposable d)
 {
     if (DisposableHelper.SetOnce(ref upstream, d))
     {
         observer.OnSubscribe(this);
     }
 }
Ejemplo n.º 9
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new RetryPredicteObserver(observer, source, times);

            observer.OnSubscribe(parent);
            parent.Next();
        }
Ejemplo n.º 10
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new ArrayDisposable(observer, array);

            observer.OnSubscribe(parent);
            parent.Run();
        }
Ejemplo n.º 11
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new JustDisposable(observer, item);

            observer.OnSubscribe(parent);
            parent.Run();
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new ConcatWithObserver(observer, other);

            observer.OnSubscribe(parent);
            parent.Subscribe(source);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Subscribes the observer to this subject and
        /// relays the live items or replays the terminal
        /// event to it.
        /// </summary>
        /// <param name="observer">The observer to dispatch signals to.</param>
        public void Subscribe(ISignalObserver <T> observer)
        {
            ValidationHelper.RequireNonNullRef(observer, nameof(observer));

            var parent = new PublishDisposable(observer, this);

            observer.OnSubscribe(parent);
            if (Add(parent))
            {
                if (parent.IsDisposed())
                {
                    Remove(parent);
                }
            }
            else
            {
                var ex = error;

                if (ex != ExceptionHelper.TERMINATED)
                {
                    parent.OnError(ex);
                }
                else
                {
                    parent.OnCompleted();
                }
            }
        }
Ejemplo n.º 14
0
        public void Subscribe(ISignalObserver <int> observer)
        {
            var parent = new RangeDisposable(observer, start, end);

            observer.OnSubscribe(parent);
            parent.Run();
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromFuncDisposable(observer);

            observer.OnSubscribe(parent);

            if (parent.IsDisposed())
            {
                return;
            }

            var v = default(T);

            try
            {
                v = supplier();
            }
            catch (Exception ex)
            {
                if (!parent.IsDisposed())
                {
                    parent.Error(ex);
                }
                return;
            }

            parent.Complete(v);
        }
        public void Subscribe(ISignalObserver <long> observer)
        {
            var parent = new IntervalDisposable(observer, start, end);

            observer.OnSubscribe(parent);

            if (initialDelay == period)
            {
                var d = scheduler.SchedulePeriodic(parent, period, t =>
                {
                    t.Run();
                });

                parent.SetTask(d);
            }
            else
            {
                var d = scheduler.Schedule((parent, period), initialDelay, (sch, state) =>
                {
                    state.parent.Run();
                    return(sch.SchedulePeriodic(state.parent, state.period, t =>
                    {
                        t.Run();
                    }));
                });

                parent.SetTask(d);
            }
        }
Ejemplo n.º 17
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromActionDisposable(observer);

            observer.OnSubscribe(parent);

            if (parent.IsDisposed())
            {
                return;
            }

            try
            {
                action();
            }
            catch (Exception ex)
            {
                if (!parent.IsDisposed())
                {
                    parent.Error(ex);
                }
                return;
            }

            parent.Complete();
        }
Ejemplo n.º 18
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new ConcatObserver(observer, sources, delayErrors);

            observer.OnSubscribe(parent);

            parent.Next();
        }
Ejemplo n.º 19
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new SwitchIfEmptyObserver(observer, fallbacks);

            observer.OnSubscribe(parent);

            parent.Run(source);
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromObserver(observer);

            observer.OnSubscribe(parent);

            parent.OnSubscribe(source.Subscribe(parent));
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new MainObserver(observer, source);

            observer.OnSubscribe(parent);

            other.Subscribe(parent.other);
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new FromTaskDisposable(observer);

            observer.OnSubscribe(parent);

            task.ContinueWith((t, o) => (parent as FromTaskDisposable).Handle(t), parent);
        }
        public void Subscribe(ISignalObserver <IObservableSource <T> > observer)
        {
            var parent = new WindowBoundaryMainObserver(observer);

            observer.OnSubscribe(parent);

            boundary.Subscribe(parent.boundary);
            source.Subscribe(parent);
        }
        public void Subscribe(ISignalObserver <TResult> observer)
        {
            var parent = new JoinCoordinator(observer, leftSelector, rightSelector, resultSelector);

            observer.OnSubscribe(parent);

            left.Subscribe(parent.leftObserver);
            right.Subscribe(parent.rightObserver);
        }
 public virtual void OnSubscribe(IDisposable d)
 {
     this.upstream = d;
     if (d is IFuseableDisposable <T> f)
     {
         this.queue = f;
     }
     downstream.OnSubscribe(this);
 }
Ejemplo n.º 26
0
        public void Subscribe(ISignalObserver <R> observer)
        {
            var srcs   = sources;
            var n      = srcs.Length;
            var parent = new ZipCoordinator(observer, mapper, delayErrors, n, capacityHint);

            observer.OnSubscribe(parent);
            parent.Subscribe(srcs);
        }
        public void Subscribe(ISignalObserver <B> observer)
        {
            var parent = new BufferBoundaryObserver(observer, bufferSupplier);

            observer.OnSubscribe(parent);

            boundary.Subscribe(parent.boundary);
            source.Subscribe(parent);
        }
Ejemplo n.º 28
0
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new TakeUntilMainObserver(observer);

            observer.OnSubscribe(parent);

            other.Subscribe(parent.other);
            source.Subscribe(parent);
        }
        public void Subscribe(ISignalObserver <T> observer)
        {
            var parent = new TimeoutObserver(observer, timeout, scheduler, fallback);

            observer.OnSubscribe(parent);

            parent.StartTimer(0);

            source.Subscribe(parent);
        }
Ejemplo n.º 30
0
        public void Subscribe(ISignalObserver <long> observer)
        {
            var parent = new TimerDisposable(observer);

            observer.OnSubscribe(parent);

            var d = scheduler.Schedule(parent, delay, (_, @this) => { @this.Run(); return(DisposableHelper.EMPTY); });

            parent.SetTask(d);
        }