Created
September 24, 2013 05:31
-
-
Save mipearson/6680724 to your computer and use it in GitHub Desktop.
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
def with_retries(timeout = 5.seconds, retry_delay: 0.1.seconds, &blk) | |
start = Time.now | |
begin | |
blk.call | |
rescue | |
if Time.now > start + timeout | |
raise | |
else | |
sleep retry_delay | |
retry | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd use
Timeout
rather than manually inspecting time, plusyield
is a slight performance increase over the block itself.