This class represents a pool of connections, you hold or release conncetions from the pool hold requests that cannot be fullfiled will be queued the fiber will be paused and resumed later when a connection is avaialble
Large portions of this class were copied and pasted form Sequel‘s threaded connection pool
Example:
pool = NeverBlock::Pool::FiberedConnectionPool.new(:size=>16) do
#connection creation code goes here
end
32.times do
Fiber.new do
conn = pool.hold # hold will pause the fiber until a connection is available
conn.execute('something') # you can use the connection normally now
en d.resume
end
The pool has support for transactions, just pass true to the pool#hold method and the connection will not be released after the block is finished It is the responsibility of client code to release the connection
| [RW] | connection_proc | a connection proc can be supplied at any time to the pool |
initialize the connection pool using the supplied proc to create the connections you can choose to start them eagerly or lazily (lazy by default)
If a connection is available, pass it to the block, otherwise pass the fiber to the queue till a connection is available when done with a connection try to porcess other fibers in the queue before releasing the connection if inside a transaction, don‘t release the fiber
Give the fiber back to the pool you have to call this explicitly if you held a connection for a transaction