Skip to content

Instantly share code, notes, and snippets.

@ttanimichi
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save ttanimichi/73ee03d5985a75c3f5d8 to your computer and use it in GitHub Desktop.

Select an option

Save ttanimichi/73ee03d5985a75c3f5d8 to your computer and use it in GitHub Desktop.
module Kernel
def yield_with_retry(limit: 3, before_retrying: ->{}, before_giving_up: ->{})
limit.times do
begin
return yield
rescue => e
before_retrying.call
end
end
before_giving_up.call
end
end
before_retrying = -> { logger.info "Failed to do something" }
before_giving_up = -> { raise "Give up to do something" }
yield_with_retry(10, before_retrying, before_giving_up)
@rastamhadi
Copy link
Copy Markdown

LGTM

@ttanimichi
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment