Created
May 28, 2013 15:35
-
-
Save okaram/5663643 to your computer and use it in GitHub Desktop.
Retrying things in ruby
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
retry_times(5,lambda{ || return 1/0;}) |
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 retry_times(n, func) | |
n=n-1 | |
return func.call() | |
rescue => e | |
puts "n=#{n} exception #{e}" | |
if n>0 then | |
retry | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment