Skip to content

Instantly share code, notes, and snippets.

@jjb
Created May 13, 2012 05:56
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 jjb/2686309 to your computer and use it in GitHub Desktop.
Save jjb/2686309 to your computer and use it in GitHub Desktop.
Usage of Timeout#timeout
require 'timeout'
begin
Timeout.timeout(1) do
# spending time doing, say, an IO operation accross the network
sleep 2
end
rescue
puts "Getting the big file took too long. Try again later."
end
➔ ruby code.rb
Getting the big file took too long. Try again later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment