public RequestProgressObservable( ISerializer serializer, ProgressToken token, IObservable <TResult> requestResult, Func <TItem, TResult, TResult> factory, CancellationToken cancellationToken, Action disposal ) { _serializer = serializer; _dataSubject = new ReplaySubject <TItem>(1); var request = requestResult .Do(_ => { }, OnError, OnCompleted) .Replay(1); _disposable = new CompositeDisposable { request.Connect(), Disposable.Create(disposal) }; _task = _dataSubject .ForkJoin(requestResult, factory) .ToTask(cancellationToken); #pragma warning disable VSTHRD105 #pragma warning disable VSTHRD110 _task.ContinueWith(_ => Dispose()); #pragma warning restore VSTHRD110 #pragma warning restore VSTHRD105 ProgressToken = token; if (_dataSubject is IDisposable disposable) { _disposable.Add(disposable); } }
public PartialItemRequestProgressObservable( ISerializer serializer, ProgressToken token, IObservable <TResult> requestResult, Func <TItem, TResult, TResult> factory, Func <TResult, TItem> reverseFactory, CancellationToken cancellationToken, Action onCompleteAction ) { _serializer = serializer; _dataSubject = new ReplaySubject <TItem>(1, Scheduler.Immediate); _disposable = new CompositeDisposable { _dataSubject }; _task = Observable.Create <TResult>( observer => new CompositeDisposable { _dataSubject .ForkJoin( requestResult .Do( _ => { if (_receivedPartialData) { return; } _dataSubject.OnNext(reverseFactory(_)); }, _dataSubject.OnError, _dataSubject.OnCompleted ), factory ) .Subscribe(observer), Disposable.Create(onCompleteAction) } ) .ToTask(cancellationToken); ProgressToken = token; }