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
- #timeout ⇒ Object
- #transition(nextstate) ⇒ 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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/httpx/timeout.rb', line 17 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 @state = :idle # this is here not to trigger the log transition(:idle) end |
Instance Attribute Details
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
15 16 17 |
# File 'lib/httpx/timeout.rb', line 15 def connect_timeout @connect_timeout end |
#operation_timeout ⇒ Object (readonly)
Returns the value of attribute operation_timeout.
15 16 17 |
# File 'lib/httpx/timeout.rb', line 15 def operation_timeout @operation_timeout end |
Class Method Details
.new(opts = {}) ⇒ Object
10 11 12 13 |
# 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
39 40 41 42 43 44 45 46 47 |
# File 'lib/httpx/timeout.rb', line 39 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/httpx/timeout.rb', line 49 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 |
#timeout ⇒ Object
33 34 35 36 37 |
# File 'lib/httpx/timeout.rb', line 33 def timeout @timeout || @total_timeout ensure log_time end |
#transition(nextstate) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/httpx/timeout.rb', line 66 def transition(nextstate) return if @state == nextstate case nextstate # when :idle when :idle @timeout = @connect_timeout when :open @timeout = @operation_timeout end @state = nextstate end |