private async Task Connect(CancellationToken cancellationToken) { await Task.Yield(); try { while (true) { using (var proxy = new ReaderProxy(_stateManager, new AsyncQueue <MessagePackage>())) await using (Stream = await _streamFactory.CreateStream(proxy, cancellationToken)) { proxy.Active(); await _stateManager.StateChangedFrom(ReaderState.Connected, cancellationToken); if (_stateManager.IsFinalState()) { return; } } } } catch (OperationCanceledException) { HasClosed(); } catch (Exception exception) { HasFaulted(exception); } }
public Reader(IConsumerStreamFactory streamFactory, IFaultStrategy faultStrategy) { _stateManager = new StateManager <ReaderState>(ReaderState.Disconnected, ReaderState.Closed, ReaderState.ReachedEndOfTopic, ReaderState.Faulted); _streamFactory = streamFactory; _faultStrategy = faultStrategy; _connectTokenSource = new CancellationTokenSource(); Stream = new NotReadyStream(); _connectTask = Connect(_connectTokenSource.Token); _throwIfClosedOrFaulted = () => { }; }
public Consumer(IConsumerStreamFactory streamFactory, IFaultStrategy faultStrategy, bool setProxyState) { _executor = new Executor(OnException); _cachedCommandAck = new CommandAck(); _stateManager = new StateManager <ConsumerState>(ConsumerState.Disconnected, ConsumerState.Closed, ConsumerState.ReachedEndOfTopic, ConsumerState.Faulted); _streamFactory = streamFactory; _faultStrategy = faultStrategy; _setProxyState = setProxyState; _connectTokenSource = new CancellationTokenSource(); Stream = new NotReadyStream(); _connectTask = Connect(_connectTokenSource.Token); _throwIfClosedOrFaulted = () => { }; }