Async::HTTP::FaradaySourceAsyncHTTPFaradayPerThreadPersistentClients

class PerThreadPersistentClients

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

Definitions

def initialize(**options, &block)

Create a new instance of the class.

Signature

parameter options Hash

The options to create the clients with.

parameter block Proc

An optional block to call with the client before it is used.

Implementation

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

def with_client(endpoint, &block)

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.

Signature

yields {|client| ...}

A client for the given endpoint.

Implementation

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

def with_proxied_client(proxy_endpoint, endpoint, &block)

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.

Signature

parameter proxy_endpoint IO::Endpoint::Generic

The proxy endpoint to use.

parameter endpoint IO::Endpoint::Generic

The endpoint to get the client for.

Implementation

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

def close

Close all clients.

This will close all clients associated with all threads.

Implementation

def close
	Thread.list.each do |thread|
		if clients = thread[@key]
			clients.close
			
			thread[@key] = nil
		end
	end
end