Class: Net::Hippie::ConnectionPool
- Inherits:
-
Object
- Object
- Net::Hippie::ConnectionPool
- Defined in:
- lib/net/hippie/connection_pool.rb
Overview
Thread-safe connection pool with LRU eviction.
Instance Method Summary collapse
- #checkout(key, &block) ⇒ Object
- #close_all ⇒ Object
-
#initialize(max_size: 100, dns_ttl: 300) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
Constructor Details
#initialize(max_size: 100, dns_ttl: 300) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
7 8 9 10 11 12 |
# File 'lib/net/hippie/connection_pool.rb', line 7 def initialize(max_size: 100, dns_ttl: 300) @max_size = max_size @dns_ttl = dns_ttl @connections = {} @monitor = Monitor.new end |
Instance Method Details
#checkout(key, &block) ⇒ Object
14 15 16 |
# File 'lib/net/hippie/connection_pool.rb', line 14 def checkout(key, &block) reuse(key) || create(key, &block) end |
#close_all ⇒ Object
18 19 20 21 22 23 |
# File 'lib/net/hippie/connection_pool.rb', line 18 def close_all @monitor.synchronize do @connections.each_value(&:close) @connections.clear end end |