Skip to content

Instantly share code, notes, and snippets.

@tkrajcar
Created August 30, 2011 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkrajcar/1181436 to your computer and use it in GitHub Desktop.
Save tkrajcar/1181436 to your computer and use it in GitHub Desktop.
ruby 1.8 open-uri timeout example
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
@tsauerwein
Copy link

Beware of the problems you can run into with timeout: http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment