Class: Fetch::ConnectionPool
- Inherits:
-
Object
- Object
- Fetch::ConnectionPool
- Defined in:
- lib/fetch/connection_pool.rb
Instance Method Summary collapse
-
#initialize ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #with_connection(uri, &block) ⇒ Object
Constructor Details
#initialize ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fetch/connection_pool.rb', line 7 def initialize @connections = {} @mutex = Mutex.new @sweeper = Thread.new { loop do sweep if @connections.empty? Thread.stop else sleep 1 end end } end |
Instance Method Details
#with_connection(uri, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/fetch/connection_pool.rb', line 24 def with_connection(uri, &block) conn = checkout(uri) begin block.call(conn) ensure checkin uri, conn end end |