Ruby for Instance / Timeouts

# Set a timeout of 1 second on the execution of the loop
Timeout::timeout(1) do
  # This loop will take 10 seconds to run
  loop do
    break if Time.now > Time.now + 10
  end
end

# The timeout will be raised before the loop finishes
# => Timeout::Error: execution expired

Try on playground

Next: defer

made with by dfxe / source / license