Created
January 24, 2016 19:13
-
-
Save rivertam/8182e72ebe76153c1799 to your computer and use it in GitHub Desktop.
Maybe a rescue?
This file contains 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
thr = Thread.new do | |
started = false | |
finished = false | |
def cleanup | |
puts '...started cleaning resource' unless started | |
started = true | |
sleep 1 | |
puts '...finished cleaning resource' unless finished | |
finished = true | |
rescue Timeout::Error | |
cleanup # just try again | |
end | |
begin | |
puts '...initializing resource' | |
sleep 1 | |
raise 'something went wrong' | |
puts '...using resource' | |
sleep 1 | |
ensure | |
cleanup | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment