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:
parent
bff870bf87
commit
e3cb08c172
1 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue