Class: Llmclt::Http::ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/llmclt/http/connection_pool.rb

Instance Method Summary collapse

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

#shutdownObject



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