Make DB::Pool accept a block

This commit is contained in:
Ary Borenszweig 2016-07-11 15:38:31 -03:00
parent fff67e86a0
commit 1cce4685ff
3 changed files with 12 additions and 12 deletions

View file

@ -29,7 +29,7 @@ module DB
pool_options = @driver.connection_pool_options(params)
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
@pool = Pool.new(->{ @driver.build_connection(self).as(Connection) }, **pool_options)
@pool = Pool.new(**pool_options) { @driver.build_connection(self).as(Connection) }
end
# Closes all connection to the database.

View file

@ -7,7 +7,7 @@ module DB
@total = [] of T
@checkout_timeout : Float64
def initialize(@factory : Proc(T), @initial_pool_size = 1, @max_pool_size = 1, @max_idle_pool_size = 1, @checkout_timeout = 5.0)
def initialize(@initial_pool_size = 1, @max_pool_size = 1, @max_idle_pool_size = 1, @checkout_timeout = 5.0, &@factory : -> T)
@initial_pool_size.times { build_resource }
@availability_channel = Channel(Nil).new