Reputation: 11
I am evaluating some code and, at times, see that the Ruby code I am executing runs over a 60 second mark.
Does anyone have an example of raising an exception based on a time limit?
Upvotes: 1
Views: 193
Reputation: 29349
require "timeout" Timeout.timeout(60) do <your code here> end
This will raise a Timeout::Error exception. You can also pass in your custom exception to the timeout:
Timeout::Error
Timeout.timeout(60, <CustomException>)
Refer to the Timeout documentation for more information.
Upvotes: 5