Module: HttpConnectionPool::Connectable::ClassMethods
- Defined in:
- lib/http_connection_pool/connectable.rb
Overview
Class-level behaviour available after include/extend.
Instance Method Summary collapse
-
#connection_pool ⇒ HttpConnectionPool::Pool
Lazy accessor for the pool — initialised on first call and memoized so the request hot path avoids re-parsing the URL and re-allocating the options hash on every ‘with_connection`.
-
#connection_pool_stats ⇒ Hash
Snapshot of the pool’s current stats.
-
#release_connection_pool ⇒ Object
Explicitly release and close this class’s pool.
-
#with_connection {|conn| ... } ⇒ Object
Borrow a connection from the pool and yield it to the block.
Instance Method Details
#connection_pool ⇒ HttpConnectionPool::Pool
Lazy accessor for the pool — initialised on first call and memoized so the request hot path avoids re-parsing the URL and re-allocating the options hash on every ‘with_connection`. The memo is dropped whenever the underlying pool has been closed (e.g. via the registry), so the next call transparently obtains a fresh pool.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/http_connection_pool/connectable.rb', line 131 def connection_pool cached = @connection_pool return cached if cached && !cached.closed? @connection_pool = HttpConnectionPool::Registry.instance.pool_for( base_url, size: pool_size, timeout: pool_timeout, ** ) end |
#connection_pool_stats ⇒ Hash
Snapshot of the pool’s current stats.
153 154 155 |
# File 'lib/http_connection_pool/connectable.rb', line 153 def connection_pool_stats connection_pool.stats end |
#release_connection_pool ⇒ Object
Explicitly release and close this class’s pool. The next call to ‘with_connection` will open a fresh pool.
145 146 147 148 |
# File 'lib/http_connection_pool/connectable.rb', line 145 def release_connection_pool @connection_pool = nil HttpConnectionPool::Registry.instance.release(base_url, **) end |
#with_connection {|conn| ... } ⇒ Object
Borrow a connection from the pool and yield it to the block.
120 121 122 |
# File 'lib/http_connection_pool/connectable.rb', line 120 def with_connection(&) connection_pool.with(&) end |