lib/ezclient/persistent_client.rb in ezclient-1.5.0 vs lib/ezclient/persistent_client.rb in ezclient-1.5.1

- old
+ new

@@ -3,12 +3,10 @@ class EzClient::PersistentClient extend Forwardable def_delegators :http_client, :build_request, :default_options, :timeout - attr_accessor :origin, :keep_alive_timeout, :last_request_at - def initialize(origin, keep_alive_timeout) self.origin = origin self.keep_alive_timeout = keep_alive_timeout self.last_request_at = nil end @@ -17,10 +15,16 @@ http_client.perform(*args).tap do self.last_request_at = EzClient.get_time end end + def timed_out? + last_request_at && EzClient.get_time - last_request_at >= keep_alive_timeout + end + private + + attr_accessor :origin, :keep_alive_timeout, :last_request_at def http_client @http_client ||= HTTP.persistent(origin, timeout: keep_alive_timeout) end end