Method: Bundler::ConnectionPool::TimedStack#pop
- Defined in:
- lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb
#pop(timeout = 0.5, options = {}) ⇒ Object
Retrieves a connection from the stack. If a connection is available it is immediately returned. If no connection is available within the given timeout a Bundler::ConnectionPool::TimeoutError is raised.
:timeout is the only checked entry in options and is preferred over the timeout argument (which will be removed in a future release). Other options may be used by subclasses that extend TimedStack.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb', line 64 def pop(timeout = 0.5, = {}) , timeout = timeout, 0.5 if Hash === timeout timeout = .fetch :timeout, timeout deadline = current_time + timeout @mutex.synchronize do loop do raise Bundler::ConnectionPool::PoolShuttingDownError if @shutdown_block return fetch_connection() if connection_stored?() connection = try_create() return connection if connection to_wait = deadline - current_time raise Bundler::ConnectionPool::TimeoutError, "Waited #{timeout} sec, #{length}/#{@max} available" if to_wait <= 0 @resource.wait(@mutex, to_wait) end end end |