Created
August 30, 2011 17:30
-
-
Save tkrajcar/1181436 to your computer and use it in GitHub Desktop.
ruby 1.8 open-uri timeout example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
timeout(2) do | |
# do whatever | |
parsed = JSON.parse(open("http://derp.com/derpservice").read) | |
end | |
end | |
rescue Timeout::Error | |
logger.debug "Timed out." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beware of the problems you can run into with
timeout
: http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/