public void OnCompleted()
            {
                if (eagerCleanup)
                {
                    var a = Interlocked.Exchange(ref resourceCleanup, null);
                    if (a != null)
                    {
                        var r = resource;
                        resource = default(S);
                        try
                        {
                            a(r);
                        }
                        catch (Exception ex)
                        {
                            downstream.OnError(ex);
                            return;
                        }
                    }

                    downstream.OnCompleted();
                }
                else
                {
                    downstream.OnCompleted();
                    CleanupAfter();
                }
            }
            public void OnError(Exception error)
            {
                if (Interlocked.CompareExchange(ref exclude, 1, 0) == 0)
                {
                    DisposableHelper.Dispose(ref task);

                    downstream.OnError(error);
                }
            }
예제 #3
0
 public void OnError(Exception error)
 {
     if (Volatile.Read(ref disposed) == 0)
     {
         downstream.OnError(error);
     }
 }
예제 #4
0
        public void Subscribe(ICompletableObserver observer)
        {
            var bd = new BooleanDisposable();

            observer.OnSubscribe(bd);

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

            try
            {
                action();
            }
            catch (Exception ex)
            {
                if (!bd.IsDisposed())
                {
                    observer.OnError(ex);
                }
                return;
            }

            if (!bd.IsDisposed())
            {
                observer.OnCompleted();
            }
        }
        /// <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);
                    }
                }
            }
        }
예제 #6
0
            public void OnError(Exception error)
            {
                var d = Interlocked.Exchange(ref resource, DisposableHelper.DISPOSED);

                if (d != DisposableHelper.DISPOSED)
                {
                    downstream.OnError(error);
                    d?.Dispose();
                }
            }
예제 #7
0
 public void OnError(Exception error)
 {
     try
     {
         downstream.OnError(error);
     }
     catch (Exception)
     {
         // TODO what should happen with these?
     }
 }
예제 #8
0
 public void OnError(Exception error)
 {
     if (delayErrors)
     {
         ExceptionHelper.AddException(ref this.errors, error);
     }
     else
     {
         DisposableHelper.WeakDispose(ref upstream);
         downstream.OnError(error);
     }
     Drain();
 }
        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);
                }
            }
        }
예제 #10
0
            public void OnError(Exception error)
            {
                var fb = default(ICompletableSource);

                try
                {
                    fb = RequireNonNullRef(handler(error), "The handler returned a null ICompletableSource");
                }
                catch (Exception ex)
                {
                    downstream.OnError(new AggregateException(error, ex));
                    return;
                }

                var inner = new CompletableInnerObserver(downstream);

                if (Interlocked.CompareExchange(ref fallbackObserver, inner, null) == null)
                {
                    fb.Subscribe(inner);
                }
            }
            void Error(Exception error, bool callTerminate)
            {
                upstream = DisposableHelper.DISPOSED;

                try
                {
                    onError?.Invoke(error);
                }
                catch (Exception ex)
                {
                    error = new AggregateException(error, ex);
                }

                if (callTerminate)
                {
                    try
                    {
                        onTerminate?.Invoke();
                    }
                    catch (Exception ex)
                    {
                        error = new AggregateException(error, ex);
                    }
                }

                downstream.OnError(error);

                try
                {
                    onAfterTerminate?.Invoke();
                }
                catch (Exception)
                {
                    // FIXME what should happen with the exception
                }

                Finally();
            }
        internal void Run()
        {
            if (CurrentCount != 0)
            {
                try
                {
                    Wait();
                }
                catch (ObjectDisposedException)
                {
                    return;
                }
            }
            var ex = error;

            if (ex != ExceptionHelper.TERMINATED)
            {
                downstream.OnError(ex);
            }
            else
            {
                downstream.OnCompleted();
            }
        }
 internal void Run()
 {
     for (; ;)
     {
         var d = Volatile.Read(ref task);
         if (d == DisposableHelper.DISPOSED)
         {
             break;
         }
         if (Interlocked.CompareExchange(ref task, DisposableHelper.EMPTY, d) == d)
         {
             var ex = error;
             if (ex != null)
             {
                 downstream.OnError(ex);
             }
             else
             {
                 downstream.OnCompleted();
             }
             break;
         }
     }
 }
예제 #14
0
 public virtual void OnError(Exception error)
 {
     downstream.OnError(error);
 }
 internal static void Error(this ICompletableObserver observer, Exception error)
 {
     observer.OnSubscribe(EMPTY);
     observer.OnError(error);
 }
 public void OnError(Exception error)
 {
     DisposableHelper.WeakDispose(ref upstream);
     downstream.OnError(error);
 }
 public void OnError(Exception error)
 {
     other = null;
     downstream.OnError(error);
 }
 public void OnError(Exception error)
 {
     next = null;
     downstream.OnError(error);
 }