Ruby retry with limit
lib/core_ext/object.rb:
class Object
def with_retry(limit)
limit.times do |i|
begin
return yield i
rescue => e
raise e if i + 1 == limit
end
end
end
end
Use case:
with_retry(5) do
make_remote_call
or_smth_other
end
Written by Eugeniy Belyaev
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#