Class: HTTPX::Timeout
- Inherits:
-
Object
- Object
- HTTPX::Timeout
- Defined in:
- lib/httpx/timeout.rb
Constant Summary collapse
- CONNECT_TIMEOUT =
60- OPERATION_TIMEOUT =
60
Instance Attribute Summary collapse
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#operation_timeout ⇒ Object
readonly
Returns the value of attribute operation_timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(connect_timeout: CONNECT_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, total_timeout: nil, loop_timeout: nil) ⇒ Timeout
constructor
A new instance of Timeout.
- #merge(other) ⇒ Object
- #no_time_left? ⇒ Boolean
- #total_timeout ⇒ Object
Constructor Details
#initialize(connect_timeout: CONNECT_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, total_timeout: nil, loop_timeout: nil) ⇒ Timeout
Returns a new instance of Timeout.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/httpx/timeout.rb', line 18 def initialize(connect_timeout: CONNECT_TIMEOUT, operation_timeout: OPERATION_TIMEOUT, total_timeout: nil, loop_timeout: nil) @connect_timeout = connect_timeout @operation_timeout = operation_timeout @total_timeout = total_timeout if loop_timeout warn ":loop_timeout is deprecated, use :operation_timeout instead" @operation_timeout = loop_timeout end reset_counter end |
Instance Attribute Details
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
16 17 18 |
# File 'lib/httpx/timeout.rb', line 16 def connect_timeout @connect_timeout end |
#operation_timeout ⇒ Object (readonly)
Returns the value of attribute operation_timeout.
16 17 18 |
# File 'lib/httpx/timeout.rb', line 16 def operation_timeout @operation_timeout end |
Class Method Details
.new(opts = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/httpx/timeout.rb', line 10 def self.new(opts = {}) return opts if opts.is_a?(Timeout) super end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/httpx/timeout.rb', line 38 def ==(other) if other.is_a?(Timeout) @connect_timeout == other.instance_variable_get(:@connect_timeout) && @operation_timeout == other.instance_variable_get(:@operation_timeout) && @total_timeout == other.instance_variable_get(:@total_timeout) else super end end |
#merge(other) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/httpx/timeout.rb', line 48 def merge(other) case other when Hash timeout = Timeout.new(other) merge(timeout) when Timeout connect_timeout = other.instance_variable_get(:@connect_timeout) || @connect_timeout operation_timeout = other.instance_variable_get(:@operation_timeout) || @operation_timeout total_timeout = other.instance_variable_get(:@total_timeout) || @total_timeout Timeout.new(connect_timeout: connect_timeout, operation_timeout: operation_timeout, total_timeout: total_timeout) else raise ArgumentError, "can't merge with #{other.class}" end end |
#no_time_left? ⇒ Boolean
65 66 67 |
# File 'lib/httpx/timeout.rb', line 65 def no_time_left? @time_left <= 0 end |
#total_timeout ⇒ Object
32 33 34 35 36 |
# File 'lib/httpx/timeout.rb', line 32 def total_timeout @total_timeout ensure log_time end |