public IConnectionHandle AcquireConnection(CancellationToken cancellationToken) { try { StartCheckingOut(); var stopwatch = Stopwatch.StartNew(); _poolQueueWaitResult = _pool._maxConnectionsQueue.WaitSignaled(_timeout, cancellationToken); if (_poolQueueWaitResult == SemaphoreSlimSignalable.SemaphoreWaitResult.Entered) { PooledConnection pooledConnection = null; var timeout = EnsureTimeout(stopwatch); using (var connectionCreator = new ConnectionCreator(_pool, timeout)) { pooledConnection = connectionCreator.CreateOpenedOrReuse(cancellationToken); } return(EndCheckingOut(pooledConnection, stopwatch)); } stopwatch.Stop(); throw CreateException(stopwatch); } catch (Exception ex) { HandleException(ex); throw; } }
public IConnectionHandle EnteredPool(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 = connectionCreator.CreateOpenedOrReuse(cancellationToken); } } return(FinalizePoolEnterance(connection)); }