Skip to content

Instantly share code, notes, and snippets.

@raul
Created October 9, 2011 21:31
Show Gist options
  • Select an option

  • Save raul/1274222 to your computer and use it in GitHub Desktop.

Select an option

Save raul/1274222 to your computer and use it in GitHub Desktop.
Removing the :growth parameter and making :interval an integer or (not AND) lambda

Time intervals between attempts

For fixed intervals, an :interval parameter can be passed indicating the time in seconds. The following example will sleep two seconds between attempts:

retry_upto(5, :interval => 2)

For customized intervals, the :interval parameter can be a lambda, which will be applied to the number of each attempt. For instance, the following code will sleep 3 seconds after the first attempt, 6 after the second, 9 after the third...

retry_upto(5, :interval => lambda{ |attempt| attempt * 3 })
@jaimeiniesta

Copy link
Copy Markdown

Sounds fine, it allows increasing and decreasing series, as well as random ones.

Btw in the example it will sleep 3, 6, 9... (not 2, 6, 9).

@raul

raul commented Oct 9, 2011

Copy link
Copy Markdown
Author

Ops, good catch! :) Glad to know you like it!

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