Skip to content

Instantly share code, notes, and snippets.

@rivertam
Created January 24, 2016 19:13
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 rivertam/8182e72ebe76153c1799 to your computer and use it in GitHub Desktop.
Save rivertam/8182e72ebe76153c1799 to your computer and use it in GitHub Desktop.
Maybe a rescue?
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