Skip to content

Commit

Permalink
Reorganize chainable timeout
Browse files Browse the repository at this point in the history
Move option transformation into then block since we want to extent it.
  • Loading branch information
stoivo committed Jun 8, 2023
1 parent 9bfcdfb commit 4e6d386
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/http/chainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,22 @@ def build_request(*args)
# @param [Numeric] global_timeout
def timeout(options)
klass, options = case options
when Numeric then [HTTP::Timeout::Global, {:global => options}]
when Hash then [HTTP::Timeout::PerOperation, options.dup]
when :null then [HTTP::Timeout::Null, {}]
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."
when Numeric then [HTTP::Timeout::Global, {global_timeout: options}]
when Hash
options = options.dup
%i[read write connect].each do |k|
next unless options.key? k

end
options["#{k}_timeout".to_sym] = options.delete k
end

%i[global read write connect].each do |k|
next unless options.key? k
[HTTP::Timeout::PerOperation, options.dup]
when :null then [HTTP::Timeout::Null, {}]
else raise ArgumentError, "Use `.timeout(:null)`, " \
"`.timeout(global_timeout_in_seconds)` or " \
"`.timeout(connect: x, write: y, read: z)`."
end

options["#{k}_timeout".to_sym] = options.delete k
end

branch default_options.merge(
:timeout_class => klass,
Expand Down

0 comments on commit 4e6d386

Please sign in to comment.