Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example HTTP gem connection pool extracted from some of my code for #ruby IRC
@executor = Concurrent::ThreadPoolExecutor.new min_threads: min_threads,
max_threads: max_threads
def connection_pool
@connection_pool ||= ConnectionPool.new size: @pool_size, timeout: @pool_timeout do
HTTP.auth("Bearer #{access_token}")
.persistent(HOST)
.timeout(@http_timeout)
.headers(accept_encoding: ACCEPT_ENCODING)
.use(:auto_inflate)
end
end
alias connect connection_pool
def disconnect
@connection_pool&.shutdown(&:close)
@connection_pool = nil
end
def future(&block)
Concurrent::Future.execute executor: @executor do
connection_pool.with(&block)
end.value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.