1
0
Fork 0
mirror of https://github.com/mperham/connection_pool synced 2023-03-27 23:22:21 -04:00

Cache options to instance variables for faster access.

Also lets the hash be GC'd.
This commit is contained in:
Damian Janowski 2012-03-14 10:24:47 -03:00
parent bff870bf87
commit e3cb08c172

View file

@ -34,8 +34,12 @@ class ConnectionPool
def initialize(options={}, &block)
raise ArgumentError, 'Connection pool requires a block' unless block
@options = DEFAULTS.merge(options)
@available = ::TimedQueue.new(options[:size], &block)
options = DEFAULTS.merge(options)
@size = options[:size] || DEFAULTS[:size]
@timeout = options[:timeout] || DEFAULTS
@available = ::TimedQueue.new(@size, &block)
@oid = @available.object_id
end
@ -50,7 +54,7 @@ class ConnectionPool
def checkout
::Thread.current[:"current-#{@oid}"] ||= begin
@available.timed_pop(@options[:timeout])
@available.timed_pop(@timeout)
end
end