-
-
Save mahendrakalkura/1e99c6620a689c8256a9ecf29bca33b1 to your computer and use it in GitHub Desktop.
Write a recursive exponential backoff service (ping) check.
This file contains 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
var ping = function() { | |
// ping... | |
}; | |
var exponentialBackoff = function(method, currentDelay, maximumDelay) { | |
var output = method(); | |
if (output) { | |
return output; | |
} | |
if (currentDelay > maximumDelay) { | |
currentDelay = maximumDelay; | |
} | |
setTimeout(function() { | |
exponentialBackoff(method, Math.pow(currentDelay, 2), maximumDelay); | |
}, currentDelay * 1000); | |
} | |
exponentialBackoff(ping, 10, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment