public async Task <IConnectionHandle> AcquireConnectionAsync(CancellationToken cancellationToken) { try { StartCheckingOut(); var stopwatch = Stopwatch.StartNew(); _poolQueueWaitResult = await _pool._maxConnectionsQueue.WaitSignaledAsync(_timeout, cancellationToken).ConfigureAwait(false); if (_poolQueueWaitResult == SemaphoreSlimSignalable.SemaphoreWaitResult.Entered) { PooledConnection pooledConnection = null; var timeout = EnsureTimeout(stopwatch); using (var connectionCreator = new ConnectionCreator(_pool, timeout)) { pooledConnection = await connectionCreator.CreateOpenedOrReuseAsync(cancellationToken).ConfigureAwait(false); } return(EndCheckingOut(pooledConnection, stopwatch)); } stopwatch.Stop(); throw CreateException(stopwatch); } catch (Exception ex) { HandleException(ex); throw; } }
public async Task <IConnectionHandle> EnteredPoolAsync(bool enteredPool, CancellationToken cancellationToken) { _enteredPool = enteredPool; PooledConnection connection = null; if (enteredPool) { var timeSpentInWaitQueue = _stopwatch.Elapsed; using (var connectionCreator = new ConnectionCreator(_pool, _pool._settings.WaitQueueTimeout - timeSpentInWaitQueue)) { connection = await connectionCreator.CreateOpenedOrReuseAsync(cancellationToken).ConfigureAwait(false); } } return(FinalizePoolEnterance(connection)); }