Class: Async::HTTP::Faraday::PerThreadPersistentClients

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

Overview

An interface for creating and managing per-thread persistent HTTP clients.

Instance Method Summary collapse

Constructor Details

#initialize(**options, &block) ⇒ PerThreadPersistentClients

Create a new instance of the class.



149
150
151
152
153
154
# File 'lib/async/http/faraday/clients.rb', line 149

def initialize(**options, &block)
	@options = options
	@block = block
	
	@key = :"#{self.class}_#{object_id}"
end

Instance Method Details

#closeObject

Close all clients.

This will close all clients associated with all threads.



178
179
180
181
182
183
184
185
186
# File 'lib/async/http/faraday/clients.rb', line 178

def close
	Thread.list.each do |thread|
		if clients = thread.thread_variable_get(@key)
			thread.thread_variable_set(@key, nil)
			
			clients.close
		end
	end
end

#with_client(endpoint, &block) ⇒ Object

Get a client for the given endpoint. If a client already exists for the host, it will be reused.

The client instance will be will be cached per-thread.



161
162
163
# File 'lib/async/http/faraday/clients.rb', line 161

def with_client(endpoint, &block)
	clients.with_client(endpoint, &block)
end

#with_proxied_client(proxy_endpoint, endpoint, &block) ⇒ Object

Get a client for the given proxy endpoint and endpoint. If a client already exists for the host, it will be reused.

The client instance will be will be cached per-thread.



171
172
173
# File 'lib/async/http/faraday/clients.rb', line 171

def with_proxied_client(proxy_endpoint, endpoint, &block)
	clients.with_proxied_client(proxy_endpoint, endpoint, &block)
end