function keepTrying(otherArgs, retryInterval, promise) { promise = promise||new Promise(); // try doing the important thing if(success) { promise.resolve(result); } else { setTimeout(function() { // Try again with incremental backoff, 2 can be // anything you want. You could even pass it in. // Cap max retry interval, which probably makes sense // in most cases. keepTrying(otherArgs, Math.min(maxRetryInterval, retryInterval * 2), promise); }, retryInterval); } }