Class: Oxblood::Pool
- Inherits:
-
Object
- Object
- Oxblood::Pool
- Defined in:
- lib/oxblood/pool.rb
Overview
Create connection pool. For the most use cases this is entrypoint API.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Pool
constructor
Initialize connection pool.
-
#with {|session| ... } ⇒ Object
Run commands on a connection from pool.
Constructor Details
#initialize(options = {}) ⇒ Pool
Initialize connection pool
20 21 22 23 24 25 26 27 |
# File 'lib/oxblood/pool.rb', line 20 def initialize( = {}) timeout = .fetch(:timeout, 1.0) size = .fetch(:size) @pool = ConnectionPool.new(size: size, timeout: timeout) do Connection.new(.fetch(:connection, {})) end end |
Instance Method Details
#with {|session| ... } ⇒ Object
Run commands on a connection from pool. Connection is wrapped to the Session.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/oxblood/pool.rb', line 40 def with conn = @pool.checkout session = Session.new(conn) yield(session) ensure if conn session.discard if conn.in_transaction? @pool.checkin end end |