Comparing version 0.12.0 to 0.13.1
@@ -18,2 +18,3 @@ function RetryOperation(timeouts, options) { | ||
this._operationStart = null; | ||
this._timer = null; | ||
@@ -28,3 +29,3 @@ if (this._options.forever) { | ||
this._attempts = 1; | ||
this._timeouts = this._originalTimeouts; | ||
this._timeouts = this._originalTimeouts.slice(0); | ||
} | ||
@@ -36,2 +37,5 @@ | ||
} | ||
if (this._timer) { | ||
clearTimeout(this._timer); | ||
} | ||
@@ -52,2 +56,3 @@ this._timeouts = []; | ||
if (err && currentTime - this._operationStart >= this._maxRetryTime) { | ||
this._errors.push(err); | ||
this._errors.unshift(new Error('RetryOperation timeout occurred')); | ||
@@ -63,5 +68,4 @@ return false; | ||
// retry forever, only keep last error | ||
this._errors.splice(this._errors.length - 1, this._errors.length); | ||
this._timeouts = this._cachedTimeouts.slice(0); | ||
timeout = this._timeouts.shift(); | ||
this._errors.splice(0, this._errors.length - 1); | ||
timeout = this._cachedTimeouts.slice(-1); | ||
} else { | ||
@@ -73,3 +77,3 @@ return false; | ||
var self = this; | ||
var timer = setTimeout(function() { | ||
this._timer = setTimeout(function() { | ||
self._attempts++; | ||
@@ -91,3 +95,3 @@ | ||
if (this._options.unref) { | ||
timer.unref(); | ||
this._timer.unref(); | ||
} | ||
@@ -94,0 +98,0 @@ |
@@ -6,3 +6,3 @@ var RetryOperation = require('./retry_operation'); | ||
return new RetryOperation(timeouts, { | ||
forever: options && options.forever, | ||
forever: options && (options.forever || options.retries === Infinity), | ||
unref: options && options.unref, | ||
@@ -55,3 +55,3 @@ maxRetryTime: options && options.maxRetryTime | ||
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt)); | ||
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt)); | ||
timeout = Math.min(timeout, opts.maxTimeout); | ||
@@ -58,0 +58,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.12.0", | ||
"version": "0.13.1", | ||
"homepage": "https://github.com/tim-kos/node-retry", | ||
@@ -13,6 +13,10 @@ "repository": { | ||
}, | ||
"files": [ | ||
"lib", | ||
"example" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"main": "index", | ||
"main": "index.js", | ||
"engines": { | ||
@@ -19,0 +23,0 @@ "node": ">= 4" |
<!-- badges/ --> | ||
[![Build Status](https://secure.travis-ci.org/tim-kos/node-retry.png?branch=master)](http://travis-ci.org/tim-kos/node-retry "Check this project's build status on TravisCI") | ||
[![Build Status](https://secure.travis-ci.org/tim-kos/node-retry.svg?branch=master)](http://travis-ci.org/tim-kos/node-retry "Check this project's build status on TravisCI") | ||
[![codecov](https://codecov.io/gh/tim-kos/node-retry/branch/master/graph/badge.svg)](https://codecov.io/gh/tim-kos/node-retry) | ||
@@ -65,3 +65,3 @@ <!-- /badges --> | ||
Creates a new `RetryOperation` object. `options` is the same as `retry.timeouts()`'s `options`, with two additions: | ||
Creates a new `RetryOperation` object. `options` is the same as `retry.timeouts()`'s `options`, with three additions: | ||
@@ -68,0 +68,0 @@ * `forever`: Whether to retry forever, defaults to `false`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
1
18852
8
271