Class: Llmclt::Http::ConnectionPool
- Inherits:
-
Object
- Object
- Llmclt::Http::ConnectionPool
- Defined in:
- lib/llmclt/http/connection_pool.rb
Instance Method Summary collapse
- #checkout(name) ⇒ Object
-
#initialize(max_size = 10) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #shutdown ⇒ Object
Constructor Details
#initialize(max_size = 10) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
6 7 8 |
# File 'lib/llmclt/http/connection_pool.rb', line 6 def initialize(max_size = 10) @max_size = max_size end |
Instance Method Details
#checkout(name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/llmclt/http/connection_pool.rb', line 10 def checkout(name) pool[name] ||= Connection.new(name: name, http: yield) conn = pool[name] conn.last_use = Time.now reduce if pool.size > @max_size conn.http end |
#shutdown ⇒ Object
21 22 23 24 |
# File 'lib/llmclt/http/connection_pool.rb', line 21 def shutdown pool.each_value(&:finish) Thread.current[:llmclt_connection] = nil end |