Created
May 13, 2012 05:56
-
-
Save jjb/2686309 to your computer and use it in GitHub Desktop.
Usage of Timeout#timeout
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
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 |
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
➔ 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