public static IDisposable SubscribeStateChange <TResult>(this IObservable <IOperationState <TResult> > self, Action <TResult> onResult = null, Action <double> onProgress = null, Action <OperationError> onError = null, Action <IOperationState <TResult> > onCompleted = null) where TResult : class { TResult result = null; ModelSource source = ModelSource.Unknown; ModelIdentifierBase id = null; double progress = 0; OperationError error = null; bool isCancelled = false; return(self .Subscribe(state => { TryFire(onProgress, ref progress, state.Progress); TryFire(onError, ref error, state.Error); if (TryFire(onResult, ref result, state.Result)) { id = state.ResultIdentifier; source = state.ResultSource; } isCancelled = state.IsCancelled; }, () => onCompleted?.Invoke(new OperationState <TResult>(result, progress, error, isCancelled, source, id)) )); }
public static IObserver <IOperationState <TResult> > OnNextError <TResult>(this IObserver <IOperationState <TResult> > self, OperationError error, double progress, ModelSource source = ModelSource.Unknown) where TResult : class { self.OnNext(new OperationState <TResult>(error: error, progress: progress, source: source)); return(self); }