Skip to content

Instantly share code, notes, and snippets.

@amalantony
Created February 12, 2017 07:55
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 amalantony/0ecb9cdb98152b93f8a06491ab793611 to your computer and use it in GitHub Desktop.
Save amalantony/0ecb9cdb98152b93f8a06491ab793611 to your computer and use it in GitHub Desktop.
function exponentialBackoff(url, retries, delay, callback) {
const success = ping(url);
if (success) {
callback(result); // successfull ping
} else {
if (retries > 0) {
setTimeOut(function() {
exponentialBackoff(url, --retries, delay * 2, callback);
}, delay);
} else {
console.log("Tried connecting", retries, "number of times, but failed.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment