Skip to content

Instantly share code, notes, and snippets.

@emberian
Created March 19, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emberian/2106760 to your computer and use it in GitHub Desktop.
Save emberian/2106760 to your computer and use it in GitHub Desktop.
/* Do `fn` `times` times every `timeout` milliseconds. Add in your own error condition handling */
function retry(fn, times, timeout) {
if (typeof fn !== 'function') {
return
}
times || (times = 3) // Third time's the charm
timeout || (timeout = 1000)
var trys = 0
function do_retry() {
if (times++ < tries) {
fn()
setTimeout(do_retry, timeout)
}
}
setTimeout(do_retry, timeout)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment