Waits on the queue up to timeout seconds, then removes and returns
the head of the queue.
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 206
def wait_poll(timeout)
@num_waiting += 1
t0 = Concurrent.monotonic_time
elapsed = 0
loop do
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
@cond.wait(timeout - elapsed)
end
return remove if any?
elapsed = Concurrent.monotonic_time - t0
if elapsed >= timeout
msg = "could not obtain a connection from the pool within %0.3f seconds (waited %0.3f seconds); all pooled connections were in use" %
[timeout, elapsed]
raise ConnectionTimeoutError, msg
end
end
ensure
@num_waiting -= 1
end