Class: RuboCop::Cop::Ezcater::RubyTimeout

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/ezcater/ruby_timeout.rb

Overview

Don’t use Timeout.timeout because it can cause transient errors

Examples:

# bad
Timeout.timeout(5) do
  ...
end

# good
expiry_time = Time.current + 5.seconds
while Time.current < expiry_time
  ...
end

Constant Summary collapse

MSG =
<<~END_MESSAGE.split("\n").join(" ")
  `Timeout.timeout` is unsafe. Find an alternative to achieve the same goal.
   Ex. Use the timeout capabilities of a networking library.
   Ex. Iterate and check runtime after each iteration.
END_MESSAGE

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/ezcater/ruby_timeout.rb', line 31

def on_send(node)
  timeout(node) do
    add_offense(node, location: :expression, message: MSG)
  end
end