Class: HTTPX::Timeout
- Inherits:
-
Object
- Object
- HTTPX::Timeout
- Defined in:
- lib/httpx/timeout.rb
Constant Summary collapse
- LOOP_TIMEOUT =
5
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(loop_timeout: LOOP_TIMEOUT, total_timeout: nil) ⇒ Timeout
constructor
A new instance of Timeout.
- #merge(other) ⇒ Object
- #timeout ⇒ Object
Constructor Details
#initialize(loop_timeout: LOOP_TIMEOUT, total_timeout: nil) ⇒ Timeout
Returns a new instance of Timeout.
14 15 16 17 18 |
# File 'lib/httpx/timeout.rb', line 14 def initialize(loop_timeout: LOOP_TIMEOUT, total_timeout: nil) @loop_timeout = loop_timeout @total_timeout = total_timeout reset_counter end |
Class Method Details
.new(opts = {}) ⇒ Object
9 10 11 12 |
# File 'lib/httpx/timeout.rb', line 9 def self.new(opts = {}) return opts if opts.is_a?(Timeout) super end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/httpx/timeout.rb', line 26 def ==(other) if other.is_a?(Timeout) @loop_timeout == other.instance_variable_get(:@loop_timeout) && @total_timeout == other.instance_variable_get(:@total_timeout) else super end end |
#merge(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/httpx/timeout.rb', line 35 def merge(other) case other when Hash timeout = Timeout.new(other) merge(timeout) when Timeout loop_timeout = other.instance_variable_get(:@loop_timeout) || @loop_timeout total_timeout = other.instance_variable_get(:@total_timeout) || @total_timeout Timeout.new(loop_timeout: loop_timeout, total_timeout: total_timeout) else raise ArgumentError, "can't merge with #{other.class}" end end |
#timeout ⇒ Object
20 21 22 23 24 |
# File 'lib/httpx/timeout.rb', line 20 def timeout @loop_timeout || @total_timeout ensure log_time end |