class Recurly::ConnectionPool
Public Class Methods
new()
click to toggle source
# File lib/recurly/connection_pool.rb, line 5 def initialize @mutex = Mutex.new @pool = [] end
Public Instance Methods
init_http_connection()
click to toggle source
# File lib/recurly/connection_pool.rb, line 30 def init_http_connection http = Net::HTTP.new(Client::BASE_HOST, Client::BASE_PORT) http.use_ssl = true http.ca_file = Client::CA_FILE http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.keep_alive_timeout = 600 http end
with_connection() { |http| ... }
click to toggle source
# File lib/recurly/connection_pool.rb, line 10 def with_connection http = nil @mutex.synchronize do http = @pool.pop end # create connection if the pool was empty http ||= init_http_connection response = yield http if http.started? @mutex.synchronize do @pool.push(http) end end response end