コード例 #1
0
        public IDisposable Subscribe(UniRx.IObserver <T> observer)
        {
            if (lastException != null)
            {
                observer.OnError(lastException);
                return(Disposable.Empty);
            }
            if (isDisposed)
            {
                observer.OnCompleted();
                return(Disposable.Empty);
            }
            if (publisher == null)
            {
                publisher = new Subject <T>();
            }
            Subject <T> subject = publisher;

            if (subject != null)
            {
                IDisposable result = subject.Subscribe(observer);
                if (canPublishValueOnSubscribe)
                {
                    observer.OnNext(value);
                }
                return(result);
            }
            observer.OnCompleted();
            return(Disposable.Empty);
        }
コード例 #2
0
        public IDisposable Subscribe(UniRx.IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception    ex           = null;
            T            value        = default(T);
            Subscription subscription = null;

            lock (observerLock)
            {
                ThrowIfDisposed();
                if (!isStopped)
                {
                    ListObserver <T> listObserver = outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        UniRx.IObserver <T> observer2 = outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            outObserver = observer;
                        }
                        else
                        {
                            outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[2]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    value        = lastValue;
                    subscription = new Subscription(this, observer);
                }
                else
                {
                    ex = lastError;
                }
            }
            if (subscription != null)
            {
                observer.OnNext(value);
                return(subscription);
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
コード例 #3
0
 public override TResult Accept <TResult>(UniRx.IObserver <T, TResult> observer)
 {
     if (observer == null)
     {
         throw new ArgumentNullException("observer");
     }
     return(observer.OnNext(Value));
 }
コード例 #4
0
 public override void Accept(UniRx.IObserver <T> observer)
 {
     if (observer == null)
     {
         throw new ArgumentNullException("observer");
     }
     observer.OnNext(Value);
 }
コード例 #5
0
 public IDisposable Subscribe(UniRx.IObserver <bool> observer)
 {
     observer.OnNext(value: true);
     observer.OnCompleted();
     return(Disposable.Empty);
 }
コード例 #6
0
 public IDisposable Subscribe(UniRx.IObserver <Unit> observer)
 {
     observer.OnNext(Unit.Default);
     observer.OnCompleted();
     return(Disposable.Empty);
 }