Adding a Timeout to a Long-Running Operation : Timeout « Development « Ruby
- Ruby
- Development
- Timeout
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