示例#1
0
            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();
                }
            }
示例#2
0
            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);
            }
示例#3
0
 public ObserverSession(IDisposable storeSession, RequestSession requestSession)
 {
     _storeSession   = storeSession;
     _requestSession = requestSession;
 }
示例#4
0
 private void BeginExecute(RequestSession session) =>
 Task.Run(() => ExecuteAsync(session));
示例#5
0
 public ObserverSession()
 {
     RequestSession = new RequestSession();
 }