Method: ConnectionPool::TimedStack#reap

Defined in:
lib/connection_pool/timed_stack.rb

#reap(idle_seconds, &block) ⇒ Object

Reaps connections that were checked in more than idle_seconds ago.

Raises:

  • (ArgumentError)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/connection_pool/timed_stack.rb', line 101

def reap(idle_seconds, &block)
  raise ArgumentError, "reap must receive a block" unless block
  raise ArgumentError, "idle_seconds must be a number" unless idle_seconds.is_a?(Numeric)
  raise ConnectionPool::PoolShuttingDownError if @shutdown_block

  idle.times do
    conn =
      @mutex.synchronize do
        raise ConnectionPool::PoolShuttingDownError if @shutdown_block

        reserve_idle_connection(idle_seconds)
      end
    break unless conn

    block.call(conn)
  end
end