Class: SingleThreadedPool
Overview
A SingleThreadedPool acts as a replacement for a ConnectionPool for use in single-threaded applications. ConnectionPool imposes a substantial performance penalty, so SingleThreadedPool is used to gain some speed.
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#connection_proc ⇒ Object
writeonly
Sets the attribute connection_proc.
Instance Method Summary collapse
-
#disconnect(&block) ⇒ Object
Disconnects from the database.
-
#hold ⇒ Object
Yields the connection to the supplied block.
-
#initialize(&block) ⇒ SingleThreadedPool
constructor
Initializes the instance with the supplied block as the connection_proc.
Constructor Details
#initialize(&block) ⇒ SingleThreadedPool
Initializes the instance with the supplied block as the connection_proc.
130 131 132 |
# File 'lib/assistance/connection_pool.rb', line 130 def initialize(&block) @connection_proc = block end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
126 127 128 |
# File 'lib/assistance/connection_pool.rb', line 126 def conn @conn end |
#connection_proc=(value) ⇒ Object (writeonly)
Sets the attribute connection_proc
127 128 129 |
# File 'lib/assistance/connection_pool.rb', line 127 def connection_proc=(value) @connection_proc = value end |
Instance Method Details
#disconnect(&block) ⇒ Object
Disconnects from the database. Once a connection is requested using #hold, the connection is reestablished.
146 147 148 149 |
# File 'lib/assistance/connection_pool.rb', line 146 def disconnect(&block) block[@conn] if block && @conn @conn = nil end |
#hold ⇒ Object
Yields the connection to the supplied block. This method simulates the ConnectionPool#hold API.
136 137 138 139 140 141 142 |
# File 'lib/assistance/connection_pool.rb', line 136 def hold @conn ||= @connection_proc.call yield @conn rescue Exception => e # if the error is not a StandardError it is converted into RuntimeError. raise e.is_a?(StandardError) ? e : e. end |