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); }
void CreateCompleted(Task <IHasTimestamp> createTask) { lock (this) { try { Value = createTask.Result; m_handleBase = Value.HandleBase; // Check if this handleBase is already present in the indexMap, and use the next index from there (else the index becomes 1) int lastIndex = 0; s_indexMap.TryGetValue(m_handleBase, out lastIndex); m_index = lastIndex + 1; // Update the indexMap with the index we used s_indexMap[m_handleBase] = m_index; Value.Changed += hasTimestamp_Changed; m_storage.Add(this); if (m_observer != null) { m_observer.OnNext(HandleName); } } catch (Exception exception) { if (m_observer != null) { m_observer.OnError(exception); } } } }
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) { 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); }
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); }
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(); } }); }
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(); }
public void OnError(Exception error) { excelObserver_.OnError(error); }
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; }