Class: Sequel::FiberedConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- Sequel::FiberedConnectionPool
- Defined in:
- lib/funapi/database/sequel/fibered_connection_pool.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #disconnect ⇒ Object
- #hold ⇒ Object
-
#initialize(db, opts = Sequel::OPTS) ⇒ FiberedConnectionPool
constructor
A new instance of FiberedConnectionPool.
Constructor Details
#initialize(db, opts = Sequel::OPTS) ⇒ FiberedConnectionPool
Returns a new instance of FiberedConnectionPool.
12 13 14 15 16 17 18 19 |
# File 'lib/funapi/database/sequel/fibered_connection_pool.rb', line 12 def initialize(db, opts = Sequel::OPTS) super @max_connections = opts[:max_connections] @available_connections = [] @notification = Async::Notification.new @size = 0 end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
49 50 51 |
# File 'lib/funapi/database/sequel/fibered_connection_pool.rb', line 49 def size @size end |
Instance Method Details
#disconnect ⇒ Object
42 43 44 45 46 47 |
# File 'lib/funapi/database/sequel/fibered_connection_pool.rb', line 42 def disconnect(*) @available_connections.each(&:close) @available_connections.clear @size = 0 end |
#hold ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/funapi/database/sequel/fibered_connection_pool.rb', line 21 def hold(*) connection = wait_for_connection return connection unless block_given? begin yield connection rescue Sequel::DatabaseDisconnectError, *@error_classes => error if disconnect_error?(error) disconnect_connection(connection) connection = nil @size -= 1 end raise ensure if connection @available_connections.push(connection) @notification.signal if Async::Task.current? end end end |