public async Task StartAsync(IChannelListener channelListener, CancellationToken cancellationToken) { if (_channelListener != null) { throw new InvalidOperationException("The client is already started"); } await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { _channelListener = channelListener ?? throw new ArgumentNullException(nameof(channelListener)); _channelListener.Start(_onDemandClientChannel); await _onDemandClientChannel.EstablishAsync(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { _logger.Error(ex, $"An error ocurred while starting the client: {ex.Message}"); throw; } finally { _semaphore.Release(); } }