Method: HTTP::Chainable#timeout

Defined in:
lib/http/chainable.rb

#timeout(options = {}) ⇒ Object #timeout(global_timeout) ⇒ Object

Overloads:

  • #timeout(options = {}) ⇒ Object

    Adds per operation timeouts to the request

    Parameters:

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :read (Float)

      Read timeout

    • :write (Float)

      Write timeout

    • :connect (Float)

      Connect timeout

  • #timeout(global_timeout) ⇒ Object

    Adds a global timeout to the full request

    Parameters:

    • global_timeout (Numeric)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/http/chainable.rb', line 93

def timeout(options)
  klass, options = case options
                   when Numeric then [HTTP::Timeout::Global, {:global => options}]
                   when Hash    then [HTTP::Timeout::PerOperation, options]
                   when :null   then [HTTP::Timeout::Null, {}]
                   else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."

                   end

  %i[global read write connect].each do |k|
    next unless options.key? k
    options["#{k}_timeout".to_sym] = options.delete k
  end

  branch default_options.merge(
    :timeout_class => klass,
    :timeout_options => options
  )
end