Exemple #1
0
        /// <summary>
        /// Subscribes the given completable observer to this subject
        /// and relays/replays the terminal events of the subject.
        /// </summary>
        /// <param name="observer">The completable observer that wants to listen to the terminal events.</param>
        public void Subscribe(ISingleObserver <T> observer)
        {
            var inner = new InnerDisposable(observer, this);

            observer.OnSubscribe(inner);

            if (Add(inner))
            {
                if (inner.IsDisposed())
                {
                    Remove(inner);
                }
            }
            else
            {
                if (!inner.IsDisposed())
                {
                    var ex = Volatile.Read(ref error);
                    if (ex == null)
                    {
                        observer.OnSuccess(value);
                    }
                    else
                    {
                        observer.OnError(ex);
                    }
                }
            }
        }
        /// <summary>
        /// Subscribes the given completable observer to this subject
        /// and relays/replays the terminal events of the subject.
        /// </summary>
        /// <param name="observer">The completable observer that wants to listen to the terminal events.</param>
        public void Subscribe(ICompletableObserver observer)
        {
            var inner = new InnerDisposable(observer, this);

            observer.OnSubscribe(inner);

            if (Add(inner))
            {
                if (inner.IsDisposed())
                {
                    Remove(inner);
                }
            }
            else
            {
                if (!inner.IsDisposed())
                {
                    var ex = Volatile.Read(ref error);
                    if (ex == ExceptionHelper.TERMINATED)
                    {
                        observer.OnCompleted();
                    }
                    else
                    {
                        observer.OnError(ex);
                    }
                }
            }
        }
        public void Subscribe(ICompletableObserver observer)
        {
            var inner = new InnerDisposable(observer, this);

            observer.OnSubscribe(inner);

            if (Add(inner))
            {
                if (inner.IsDisposed())
                {
                    Remove(inner);
                }
            }
            else
            {
                if (!inner.IsDisposed())
                {
                    var ex = Volatile.Read(ref error);
                    if (ex == ExceptionHelper.TERMINATED)
                    {
                        observer.OnCompleted();
                    }
                    else
                    {
                        observer.OnError(ex);
                    }
                }
                return;
            }

            var src = Volatile.Read(ref source);

            if (src != null)
            {
                src = Interlocked.Exchange(ref source, null);
                if (src != null)
                {
                    var a = cancel;
                    cancel = null;
                    a?.Invoke(this);

                    src.Subscribe(this);
                }
            }
        }