class ActiveRecord::ConnectionAdapters::ConnectionPool

def try_to_checkout_new_connection

Experimental RBS support (using type sampling data from the type_fusion project).

def try_to_checkout_new_connection: () -> ActiveRecord::ConnectionAdapters::SQLite3Adapter

This signature was generated using 1 sample from 1 application.

method must be in the +.leased+ state.
Implementation constraint: a newly established connection returned by this
--
to the DB is done outside main synchronized section.
If the pool is not at a @size limit, establish new connection. Connecting
def try_to_checkout_new_connection
  # first in synchronized section check if establishing new conns is allowed
  # and increment @now_connecting, to prevent overstepping this pool's @size
  # constraint
  do_checkout = synchronize do
    if @threads_blocking_new_connections.zero? && (@connections.size + @now_connecting) < @size
      @now_connecting += 1
    end
  end
  if do_checkout
    begin
      # if successfully incremented @now_connecting establish new connection
      # outside of synchronized section
      conn = checkout_new_connection
    ensure
      synchronize do
        if conn
          adopt_connection(conn)
          # returned conn needs to be already leased
          conn.lease
        end
        @now_connecting -= 1
      end
    end
  end
end