retry
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -1,3 +0,9 @@ | ||
function RetryOperation(timeouts, retryForever) { | ||
function RetryOperation(timeouts, options) { | ||
// Compatibility for the old (timeouts, retryForever) signature | ||
if (typeof options === 'boolean') { | ||
options = { forever: options }; | ||
} | ||
this._timeouts = timeouts; | ||
this._options = options || {}; | ||
this._fn = null; | ||
@@ -10,3 +16,3 @@ this._errors = []; | ||
if (!!retryForever) { | ||
if (this._options.forever) { | ||
this._cachedTimeouts = this._timeouts.slice(0); | ||
@@ -41,3 +47,3 @@ } | ||
var self = this; | ||
setTimeout(function() { | ||
var timer = setTimeout(function() { | ||
self._attempts++; | ||
@@ -49,2 +55,6 @@ | ||
}, self._operationTimeout); | ||
if (this._options.unref) { | ||
self._timeout.unref(); | ||
} | ||
} | ||
@@ -55,2 +65,6 @@ | ||
if (this._options.unref) { | ||
timer.unref(); | ||
} | ||
return true; | ||
@@ -57,0 +71,0 @@ }; |
var RetryOperation = require('./retry_operation'); | ||
exports.operation = function(options) { | ||
var retryForever = false; | ||
if (options && options.forever === true) retryForever = true; | ||
var timeouts = exports.timeouts(options); | ||
return new RetryOperation(timeouts, retryForever); | ||
return new RetryOperation(timeouts, { | ||
forever: options && options.forever, | ||
unref: options && options.unref | ||
}); | ||
}; | ||
@@ -9,0 +10,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"homepage": "https://github.com/tim-kos/node-retry", | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -60,5 +60,7 @@ # retry | ||
Creates a new `RetryOperation` object. See the `retry.timeouts()` function | ||
below for available `options`. | ||
Creates a new `RetryOperation` object. `options` is the same as `retry.timeouts()`'s `options`, with two additions: | ||
* `forever`: Whether to retry forever, defaults to `false`. | ||
* `unref`: Wether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. | ||
### retry.timeouts([options]) | ||
@@ -130,3 +132,3 @@ | ||
### new RetryOperation(timeouts) | ||
### new RetryOperation(timeouts, [options]) | ||
@@ -136,2 +138,10 @@ Creates a new `RetryOperation` where `timeouts` is an array where each value is | ||
Available options: | ||
* `forever`: Whether to retry forever, defaults to `false`. | ||
* `unref`: Wether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's, defaults to `false`. | ||
If `forever` is true, the following changes happen: | ||
* `RetryOperation.errors()` will only output an array of one item: the last error. | ||
* `RetryOperation` will repeatedly use the last item in the `timeouts` array. | ||
#### retryOperation.errors() | ||
@@ -163,7 +173,7 @@ | ||
This is an alias for `retryOperation.attempt(fn)`. This is deprecated. | ||
This is an alias for `retryOperation.attempt(fn)`. This is deprecated. Please use `retryOperation.attempt(fn)` instead. | ||
#### retryOperation.start(fn) | ||
This is an alias for `retryOperation.attempt(fn)`. This is deprecated. | ||
This is an alias for `retryOperation.attempt(fn)`. This is deprecated. Please use `retryOperation.attempt(fn)` instead. | ||
@@ -187,10 +197,12 @@ #### retryOperation.retry(error) | ||
#Changelog | ||
# Changelog | ||
0.7.0 Some bugfixes and made retry.createTimeout() public. Fixed issues [#10](https://github.com/tim-kos/node-retry/issues/10), [#12](https://github.com/tim-kos/node-retry/issues/12), and [#13](https://github.com/tim-kos/node-retry/issues/13). | ||
0.8.0 Implementing retry.wrap. | ||
0.6.0 Introduced optional timeOps parameter for the attempt() function which is an object having a property timeout in miliseconds and a property cb callback function. Whenever your retry operation takes longer than timeout to execute, the timeout callback function cb is called. | ||
0.7.0 Some bug fixes and made retry.createTimeout() public. Fixed issues [#10](https://github.com/tim-kos/node-retry/issues/10), [#12](https://github.com/tim-kos/node-retry/issues/12), and [#13](https://github.com/tim-kos/node-retry/issues/13). | ||
0.5.0 Some minor refactorings. | ||
0.6.0 Introduced optional timeOps parameter for the attempt() function which is an object having a property timeout in milliseconds and a property cb callback function. Whenever your retry operation takes longer than timeout to execute, the timeout callback function cb is called. | ||
0.5.0 Some minor refactoring. | ||
0.4.0 Changed retryOperation.try() to retryOperation.attempt(). Deprecated the aliases start() and try() for it. | ||
@@ -197,0 +209,0 @@ |
23695
436
208