# File lib/connection_pool/timed_stack.rb, line 62 def empty? (@created - @que.length) >= @max end
# File lib/connection_pool/timed_stack.rb, line 66 def length @max - @created + @que.length end
# File lib/connection_pool/timed_stack.rb, line 31 def pop(timeout=0.5) deadline = Time.now + timeout @mutex.synchronize do loop do raise ConnectionPool::PoolShuttingDownError if @shutdown_block return @que.pop unless @que.empty? unless @created == @max @created += 1 return @create_block.call end to_wait = deadline - Time.now raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0 @resource.wait(@mutex, to_wait) end end end
# File lib/connection_pool/timed_stack.rb, line 18 def push(obj) @mutex.synchronize do if @shutdown_block @shutdown_block.call(obj) else @que.push obj end @resource.broadcast end end
# File lib/connection_pool/timed_stack.rb, line 48 def shutdown(&block) raise ArgumentError, "shutdown must receive a block" unless block_given? @mutex.synchronize do @shutdown_block = block @resource.broadcast @que.size.times do conn = @que.pop block.call(conn) end end end
Generated with the Darkfish Rdoc Generator 2.