diff --git a/lib/retry.js b/lib/retry.js index 5e85e79..4e405d4 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -1,11 +1,16 @@ var RetryOperation = require('./retry_operation'); exports.operation = function(options) { + if (options) { + options.forever = options && (options.forever || options.retries === Infinity); + options.retries = options && (options.forever ? undefined : options.retries); + } + var timeouts = exports.timeouts(options); return new RetryOperation(timeouts, { - forever: options && (options.forever || options.retries === Infinity), - unref: options && options.unref, - maxRetryTime: options && options.maxRetryTime + forever: options && options.forever, + unref: options && options.unref, + maxRetryTime: options && options.maxRetryTime }); }; @@ -22,7 +27,9 @@ exports.timeouts = function(options) { randomize: false }; for (var key in options) { - opts[key] = options[key]; + if (options[key]) { + opts[key] = options[key]; + } } if (opts.minTimeout > opts.maxTimeout) { diff --git a/test/integration/test-forever.js b/test/integration/test-forever.js index b41307c..3a5a440 100644 --- a/test/integration/test-forever.js +++ b/test/integration/test-forever.js @@ -22,3 +22,19 @@ var retry = require(common.dir.lib + '/retry'); } }); })(); + +(function testRetriesInfinity() { + const operation = retry.operation({ + retries: Infinity, + minTimeout: 100, + maxTimeout: 100, + }); + + operation.attempt(function (numAttempt) { + if (numAttempt == 10) { + operation.stop(); + } + + operation.retry(new Error('foo')); + }); +})();