Created
February 12, 2017 07:55
-
-
Save amalantony/0ecb9cdb98152b93f8a06491ab793611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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