Class: FiberConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- FiberConnectionPool
- Defined in:
- lib/thrift_client/pool/fiber_connection_pool.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy all connections in this pool.
-
#execute ⇒ Object
Choose first idle connection and pass it to the supplied block.
-
#initialize(opts, &block) ⇒ FiberConnectionPool
constructor
A new instance of FiberConnectionPool.
Methods inherited from ConnectionPool
Constructor Details
#initialize(opts, &block) ⇒ FiberConnectionPool
Returns a new instance of FiberConnectionPool.
6 7 8 |
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 6 def initialize(opts, &block) super end |
Instance Method Details
#destroy ⇒ Object
Destroy all connections in this pool. It will waiting until all connections are idle and than close them one by one.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 25 def destroy while @idle.size < @size fiber = Fiber.current @pending.push fiber Fiber.yield end @idle.each do | conn | begin conn.disconnect rescue Exception => e puts "close connection error! #{e.backtrace}" end end end |
#execute ⇒ Object
Choose first idle connection and pass it to the supplied block. This will block indefinitely until there is an idle connection to service the request.
13 14 15 16 17 18 19 20 21 |
# File 'lib/thrift_client/pool/fiber_connection_pool.rb', line 13 def execute f = Fiber.current begin conn = acquire(f) yield conn ensure release(f) end end |