Module: Synctest::Patches::TimeoutPatch

Defined in:
lib/synctest/patches.rb

Instance Method Summary collapse

Instance Method Details

#timeout(seconds, exception_class = nil, message = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/synctest/patches.rb', line 553

def timeout(seconds, exception_class = nil, message = nil, &block)
  bubble = Synctest.current_bubble
  return super unless bubble
  return block.call(seconds) if seconds.nil? || seconds.zero?

  raise ArgumentError, "Timeout sec must be a non-negative number" if seconds.negative?

  message ||= "execution expired"
  if exception_class
    Patches.run_timeout_timer(seconds, exception_class, message, &block)
  else
    Timeout::Error.handle_timeout(message) do |exception|
      Patches.run_timeout_timer(seconds, exception, message, &block)
    end
  end
end