Count for five second : Timeout « Development « Ruby






Count for five second

require 'timeout'
def count_for_five_seconds
  $counter = 0
  begin
    Timeout::timeout(5) { loop { $counter += 1 } }
  rescue Timeout::Error
    puts "count to #{$counter} in 5 seconds."
  end
end
count_for_five_seconds
puts $counter

 








Related examples in the same category

1.Adding a Timeout to a Long-Running Operation