public override async Task <IBleResult> StartObservingAsync(IObserverBehavior <T> decoratedObserver, CancellationToken cancellationToken) { IBleResult result; try { if (_connector.IsConnected) { result = await decoratedObserver.StartObservingAsync(cancellationToken).ConfigureAwait(false); } else { var connectionResult = await _connector.ConnectAsync(cancellationToken); if (connectionResult.IsOperationCompleted) { cancellationToken.ThrowIfCancellationRequested(); result = await decoratedObserver.StartObservingAsync(cancellationToken); } else { result = BleResult.Failure(BleFailure.DeviceNotConnected, connectionResult); } } } catch (OperationCanceledException) { result = BleResult.Failure(BleFailure.OperationCancelled); } return(result); }
public virtual Task <IBleResult> StartObservingAsync(IObserverBehavior <TObserver> decoratedObserver, CancellationToken cancellationToken) { return(decoratedObserver.StartObservingAsync(cancellationToken)); }