Example #1
0
        private async Task EnsureMinSizeAsync(CancellationToken cancellationToken)
        {
            var minTimeout = TimeSpan.FromMilliseconds(20);

            while (CreatedCount < _settings.MinConnections && !cancellationToken.IsCancellationRequested)
            {
                using (var poolAwaiter = _maxConnectionsQueue.CreateAwaiter())
                {
                    var entered = await poolAwaiter.WaitSignaledAsync(minTimeout, cancellationToken).ConfigureAwait(false);

                    if (!entered)
                    {
                        return;
                    }

                    using (var connectionCreator = new ConnectionCreator(this, minTimeout))
                    {
                        var connection = await connectionCreator.CreateOpenedAsync(cancellationToken).ConfigureAwait(false);

                        _connectionHolder.Return(connection);
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
Example #2
0
 // internal methods
 internal SemaphoreSlimSignalable.SemaphoreSlimSignalableAwaiter CreateMaxConnectionsAwaiter()
 {
     return(_maxConnectionsQueue.CreateAwaiter());
 }