Example #1
0
        public IDisposable Subscribe(IExcelObserver observer)
        {
            lock (_observerLock)
            {
                if (_observer != null)
                {
                    throw new InvalidOperationException("Only single Subscription allowed.");
                }
                _observer = observer;

                if (_hasResult)
                {
                    if (_exception != null)
                    {
                        _observer.OnError(_exception);
                    }
                    else
                    {
                        _observer.OnNext(_result);
                        _observer.OnCompleted();
                    }
                }
            }

            return(DummyDisposable.Instance);
        }
Example #2
0
        public IDisposable Subscribe(IExcelObserver observer)
        {
            if (_subscribed)
            {
                throw new InvalidOperationException("Only single Subscription allowed.");
            }
            _subscribed = true;

            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    object result = _func();
                    observer.OnNext(result);
                    observer.OnCompleted();
                }
                catch (Exception ex)
                {
                    // TODO: Log somehow?
                    observer.OnError(ex);
                }
            });

            return(DummyDisposable.Instance);
        }
            public IDisposable Subscribe(IExcelObserver observer)
            {
                switch (_task.Status)
                {
                case TaskStatus.RanToCompletion:
                    observer.OnNext(_task.Result);
                    observer.OnCompleted();
                    break;

                case TaskStatus.Faulted:
                    observer.OnError(_task.Exception.InnerException);
                    break;

                case TaskStatus.Canceled:
                    observer.OnError(new TaskCanceledException(_task));
                    break;

                default:
                    _task.ContinueWith(t =>
                    {
                        switch (t.Status)
                        {
                        case TaskStatus.RanToCompletion:
                            observer.OnNext(t.Result);
                            observer.OnCompleted();
                            break;

                        case TaskStatus.Faulted:
                            observer.OnError(t.Exception.InnerException);
                            break;

                        case TaskStatus.Canceled:
                            observer.OnError(new TaskCanceledException(t));
                            break;
                        }
                    });
                    break;
                }

                // Check for cancellation support
                if (_cts != null)
                {
                    return(new CancellationDisposable(_cts));
                }
                // No cancellation
                return(DefaultDisposable.Instance);
            }
Example #4
0
            public IDisposable Subscribe(IExcelObserver observer)
            {
                switch (_task.Status)
                {
                case TaskStatus.RanToCompletion:
                    observer.OnNext(_task.Result);
                    observer.OnCompleted();
                    break;

                case TaskStatus.Faulted:
                    observer.OnError(_task.Exception.InnerException);
                    break;

                case TaskStatus.Canceled:
                    observer.OnError(new TaskCanceledException(_task));
                    break;

                default:
                    var task = _task;
                    // OK - the Task has not completed synchronously
                    // And handle the Task completion
                    task.ContinueWith(t =>
                    {
                        switch (t.Status)
                        {
                        case TaskStatus.RanToCompletion:
                            observer.OnNext(t.Result);
                            observer.OnCompleted();
                            break;

                        case TaskStatus.Faulted:
                            observer.OnError(t.Exception.InnerException);
                            break;

                        case TaskStatus.Canceled:
                            observer.OnError(new TaskCanceledException(t));
                            break;
                        }
                    });
                    break;
                }

                return(DefaultDisposable.Instance);
            }
Example #5
0
 protected CalcWrapperObservableBase(ExcelCalcWrapper calcWrapper)
 {
     _calcWrapper = calcWrapper;
     _calcWrapper.CalcTask.ContinueWith(task =>
     {
         if (task.IsFaulted) // TODO what about cancelled
         {
             _observer?.OnError(task.Exception.InnerException);
         }
         else
         {
             _observer?.OnCompleted();
         }
     });
 }
Example #6
0
        public IDisposable Subscribe(IExcelObserver observer)
        {
            lock (_observerLock)
            {
                if (_observer != null) throw new InvalidOperationException("Only single Subscription allowed.");
                _observer = observer;

                if (_hasResult)
                {
                    if (_exception != null)
                    {
                        _observer.OnError(_exception);
                    }
                    else
                    {
                        _observer.OnNext(_result);
                        _observer.OnCompleted();
                    }
                }
            }

            return DummyDisposable.Instance;
        }
            public IDisposable Subscribe(IExcelObserver observer)
            {
                // Start with a disposable that does nothing
                // Possibly set to a CancellationDisposable later
                IDisposable disp = DefaultDisposable.Instance;

                switch (_task.Status)
                {
                case TaskStatus.RanToCompletion:
                    observer.OnNext(_task.Result);
                    observer.OnCompleted();
                    break;

                case TaskStatus.Faulted:
                    observer.OnError(_task.Exception.InnerException);
                    break;

                case TaskStatus.Canceled:
                    observer.OnError(new TaskCanceledException(_task));
                    break;

                default:
                    var task = _task;
                    // OK - the Task has not completed synchronously
                    // First set up a continuation that will suppress Cancel after the Task completes
                    if (_cts != null)
                    {
                        var cancelDisp = new CancellationDisposable(_cts);
                        task = _task.ContinueWith(t =>
                        {
                            cancelDisp.SuppressCancel();
                            return(t);
                        }).Unwrap();

                        // Then this will be the IDisposable we return from Subscribe
                        disp = cancelDisp;
                    }
                    // And handle the Task completion
                    task.ContinueWith(t =>
                    {
                        switch (t.Status)
                        {
                        case TaskStatus.RanToCompletion:
                            observer.OnNext(t.Result);
                            observer.OnCompleted();
                            break;

                        case TaskStatus.Faulted:
                            observer.OnError(t.Exception.InnerException);
                            break;

                        case TaskStatus.Canceled:
                            observer.OnError(new TaskCanceledException(t));
                            break;
                        }
                    });
                    break;
                }

                return(disp);
            }
        public IDisposable Subscribe(IExcelObserver observer)
        {
            if (_subscribed) throw new InvalidOperationException("Only single Subscription allowed.");
            _subscribed = true;

            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    object result = _func();
                    observer.OnNext(result);
                    observer.OnCompleted();
                }
                catch (Exception ex)
                {
                    // TODO: Log somehow
                    observer.OnError(ex);
                }
            });

            return new DummyDisposable();
        }
Example #9
0
 public void OnCompleted()
 {
     excelObserver_.OnCompleted();
 }
            public IDisposable Subscribe(IExcelObserver observer)
            {
                switch (_task.Status)
                {
                    case TaskStatus.RanToCompletion:
                        observer.OnNext(_task.Result);
                        observer.OnCompleted();
                        break;
                    case TaskStatus.Faulted:
                        observer.OnError(_task.Exception.InnerException);
                        break;
                    case TaskStatus.Canceled:
                        observer.OnError(new TaskCanceledException(_task));
                        break;
                    default:
                        var task = _task;
                        // OK - the Task has not completed synchronously
                        // And handle the Task completion
                        task.ContinueWith(t =>
                        {
                            switch (t.Status)
                            {
                                case TaskStatus.RanToCompletion:
                                    observer.OnNext(t.Result);
                                    observer.OnCompleted();
                                    break;
                                case TaskStatus.Faulted:
                                    observer.OnError(t.Exception.InnerException);
                                    break;
                                case TaskStatus.Canceled:
                                    observer.OnError(new TaskCanceledException(t));
                                    break;
                            }
                        });
                        break;
                }

                return DefaultDisposable.Instance;
            }