private async Task ExecuteAsync(RequestSession session) { try { IOperationResultBuilder <TData, TResult> resultBuilder = _resultBuilder(); await foreach (var response in _connection.ExecuteAsync(_request, session.Token).ConfigureAwait(false)) { if (session.Token.IsCancellationRequested) { return; } _operationStore.Set(_request, resultBuilder.Build(response)); } } finally { session.Dispose(); } }
public IDisposable Subscribe( IObserver <IOperationResult <TResult> > observer) { var hasResultInStore = false; if ((_strategy == ExecutionStrategy.CacheFirst || _strategy == ExecutionStrategy.CacheAndNetwork) && _operationStore.TryGet(_request, out IOperationResult <TResult>?result)) { hasResultInStore = true; observer.OnNext(result); } IDisposable session = _operationStore.Watch <TResult>(_request).Subscribe(observer); if (_strategy != ExecutionStrategy.CacheFirst || !hasResultInStore) { var requestSession = new RequestSession(); BeginExecute(requestSession); return(new ObserverSession(session, requestSession)); } return(session); }
public ObserverSession(IDisposable storeSession, RequestSession requestSession) { _storeSession = storeSession; _requestSession = requestSession; }
private void BeginExecute(RequestSession session) => Task.Run(() => ExecuteAsync(session));
public ObserverSession() { RequestSession = new RequestSession(); }