Skip to content

Instantly share code, notes, and snippets.

@dbalduini
Created August 26, 2016 13:36
Show Gist options
  • Save dbalduini/86f46923ae934dd286c0ccec4cef5d80 to your computer and use it in GitHub Desktop.
Save dbalduini/86f46923ae934dd286c0ccec4cef5d80 to your computer and use it in GitHub Desktop.
persistent task in node
// The task will be re-runed after delay seconds
// if retry() is called by the caller
persistentTask = function (delay, maxRetries, task) {
function retry () {
if (maxRetries > 0) {
maxRetries = maxRetries - 1;
setTimeout(function () {
task(retry);
}, delay);
} else {
console.log("Max number of retries reached!");
}
}
task(retry);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment