Adding a Timeout to a Long-Running Operation : Timeout « Development « Ruby






Adding a Timeout to a Long-Running Operation


require 'timeout'
before = Time.now
begin
  status = Timeout.timeout(5) { sleep }
rescue Timeout::Error
  puts "I only slept for #{Time.now-before} seconds."
end

 








Related examples in the same category

1.Count for five second