public async Task CloseAsync(TimeSpan timeout) { Logging.Enter(this, timeout, nameof(CloseAsync)); bool enteredSemaphore = await _sessionSemaphore.WaitAsync(timeout).ConfigureAwait(false); if (!enteredSemaphore) { throw new TimeoutException("Failed to enter the semaphore required for closing an AMQP session."); } try { if (_amqpIotSession != null && !_amqpIotSession.IsClosing()) { try { await _amqpIotSession.CloseAsync(timeout).ConfigureAwait(false); } finally { Cleanup(); } } } finally { _closed = true; Logging.Exit(this, timeout, nameof(CloseAsync)); _sessionSemaphore.Release(); } }
public async Task CloseAsync(CancellationToken cancellationToken) { if (Logging.IsEnabled) { Logging.Enter(this, nameof(CloseAsync)); } try { await _sessionSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { throw new TimeoutException("Failed to enter the semaphore required for closing an AMQP session."); } try { if (_amqpIotSession != null && !_amqpIotSession.IsClosing()) { try { await _amqpIotSession.CloseAsync(cancellationToken).ConfigureAwait(false); } finally { Cleanup(); } } } finally { _closed = true; if (Logging.IsEnabled) { Logging.Exit(this, nameof(CloseAsync)); } _sessionSemaphore.Release(); } }