class Async::Postgres::Pool
This pool doesn't impose a maximum number of open resources, but it WILL block if there are no available resources and trying to allocate another one fails.
Public Class Methods
new(&block)
click to toggle source
# File lib/async/postgres/pool.rb, line 65 def initialize(&block) @available = [] @waiting = [] @constructor = block end
Public Instance Methods
acquire() { |resource| ... }
click to toggle source
# File lib/async/postgres/pool.rb, line 72 def acquire resource = wait_for_next_available begin yield resource ensure @available << resource if task = @waiting.pop task.resume end end end
close()
click to toggle source
# File lib/async/postgres/pool.rb, line 86 def close @available.each(&:close) @available.clear end
next_available()
click to toggle source
# File lib/async/postgres/pool.rb, line 100 def next_available if @available.empty? return @constructor.call # This might fail, which is okay :) else return @available.pop end rescue StandardError $stderr.puts $!.inspect return nil end
wait_for_next_available()
click to toggle source
# File lib/async/postgres/pool.rb, line 91 def wait_for_next_available until resource = next_available @waiting << Fiber.current Task.yield end return resource end