Class: Async::HTTP::Faraday::PersistentClients

Inherits:
Clients
  • Object
show all
Defined in:
lib/async/http/faraday/clients.rb

Overview

An interface for creating and managing persistent HTTP clients.

Instance Method Summary collapse

Methods inherited from Clients

call

Constructor Details

#initializePersistentClients

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

#closeObject

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.

Yields:



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.

Yields:

  • (proxied_client)


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