Created
February 27, 2013 05:14
-
-
Save clicube/5045288 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
LIMIT = {} | |
def limit n | |
key = [caller,Thread.current] | |
LIMIT[key] ||= n | |
LIMIT[key] -= 1 | |
n = LIMIT[key] | |
if n > 0 | |
n | |
else | |
LIMIT.delete key | |
nil | |
end | |
end | |
class CustomError < StandardError;end | |
begin | |
raise CustomError, "nyan" if rand() < 0.95 | |
p "wan!" | |
rescue CustomError => e | |
p e | |
retry if limit 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使えません