Skip to content

Commit 4e6d386

Browse files
committed
Reorganize chainable timeout
Move option transformation into then block since we want to extent it.
1 parent 9bfcdfb commit 4e6d386

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/http/chainable.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,22 @@ def build_request(*args)
9292
# @param [Numeric] global_timeout
9393
def timeout(options)
9494
klass, options = case options
95-
when Numeric then [HTTP::Timeout::Global, {:global => options}]
96-
when Hash then [HTTP::Timeout::PerOperation, options.dup]
97-
when :null then [HTTP::Timeout::Null, {}]
98-
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."
95+
when Numeric then [HTTP::Timeout::Global, {global_timeout: options}]
96+
when Hash
97+
options = options.dup
98+
%i[read write connect].each do |k|
99+
next unless options.key? k
99100

100-
end
101+
options["#{k}_timeout".to_sym] = options.delete k
102+
end
101103

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

105-
options["#{k}_timeout".to_sym] = options.delete k
106-
end
107111

108112
branch default_options.merge(
109113
:timeout_class => klass,

0 commit comments

Comments
 (0)