Class: Async::HTTP::Faraday::PersistentClients
- Defined in:
- lib/async/http/faraday/clients.rb
Overview
An interface for creating and managing persistent HTTP clients.
Instance Method Summary collapse
-
#close ⇒ Object
Close all clients.
-
#initialize ⇒ PersistentClients
constructor
Create a new instance of the class.
-
#make_client(endpoint) ⇒ Object
Lookup or create a client for the given endpoint.
-
#with_client(endpoint) {|make_client(endpoint)| ... } ⇒ Object
Get a client for the given endpoint.
-
#with_proxied_client(proxy_endpoint, endpoint) {|proxied_client| ... } ⇒ Object
Get a client for the given proxy endpoint and endpoint.
Methods inherited from Clients
Constructor Details
#initialize ⇒ PersistentClients
Create a new instance of the class.
76 77 78 79 80 |
# File 'lib/async/http/faraday/clients.rb', line 76 def initialize(...) super @clients = {} end |
Instance Method Details
#close ⇒ Object
Close all clients.
83 84 85 86 87 88 89 90 |
# File 'lib/async/http/faraday/clients.rb', line 83 def close super clients = @clients.values @clients.clear clients.reverse_each(&:close) end |
#make_client(endpoint) ⇒ Object
Lookup or create a client for the given endpoint.
95 96 97 98 99 100 101 |
# File 'lib/async/http/faraday/clients.rb', line 95 def make_client(endpoint) key = host_key(endpoint) fetch(key) do super end end |
#with_client(endpoint) {|make_client(endpoint)| ... } ⇒ Object
Get a client for the given endpoint. If a client already exists for the host, it will be reused.
106 107 108 |
# File 'lib/async/http/faraday/clients.rb', line 106 def with_client(endpoint) yield make_client(endpoint) end |
#with_proxied_client(proxy_endpoint, endpoint) {|proxied_client| ... } ⇒ Object
Get a client for the given proxy endpoint and endpoint. If a client already exists for the host, it will be reused.
114 115 116 117 118 119 120 121 122 |
# File 'lib/async/http/faraday/clients.rb', line 114 def with_proxied_client(proxy_endpoint, endpoint) key = [host_key(proxy_endpoint), host_key(endpoint)] proxied_client = fetch(key) do make_client(proxy_endpoint).proxied_client(endpoint) end yield proxied_client end |