/// <inheritdocs /> public async Task <IOperationResult <TResult> > ExecuteAsync( OperationRequest request, CancellationToken cancellationToken = default) { if (request is null) { throw new ArgumentNullException(nameof(request)); } IOperationResult <TResult>?result = null; IOperationResultBuilder <TData, TResult> resultBuilder = _resultBuilder(); await foreach (var response in _connection.ExecuteAsync(request, cancellationToken)) { result = resultBuilder.Build(response); _operationStore.Set(request, result); } if (result is null) { throw new InvalidOperationException(HttpOperationExecutor_ExecuteAsync_NoResult); } return(result); }
private async Task ExecuteAsync( IObserver <IOperationResult <TResult> > observer, ObserverSession session) { try { CancellationToken token = session.RequestSession.Token; IOperationResultBuilder <TData, TResult> resultBuilder = _resultBuilder(); await foreach (var response in _connection.ExecuteAsync(_request, token).ConfigureAwait(false)) { if (token.IsCancellationRequested) { return; } IOperationResult <TResult> result = resultBuilder.Build(response); _operationStore.Set(_request, result); if (!session.HasStoreSession) { observer.OnNext(result); IDisposable storeSession = _operationStore .Watch <TResult>(_request) .Subscribe(observer); try { session.SetStoreSession(storeSession); } catch (ObjectDisposedException) { storeSession.Dispose(); throw; } } } } catch (Exception ex) { observer.OnError(ex); } finally { // after all the transport logic is finished we will dispose // the request session. session.RequestSession.Dispose(); } }