async-retry-ng
Advanced tools
Comparing version 1.0.2 to 2.0.0
function RetryOperation(timeouts, options) { | ||
// Compatibility for the old (timeouts, retryForever) signature | ||
if (typeof options === "boolean") { | ||
if (typeof options === 'boolean') { | ||
options = { forever: options }; | ||
@@ -25,3 +25,3 @@ } | ||
RetryOperation.prototype.reset = function() { | ||
RetryOperation.prototype.reset = function reset() { | ||
this._attempts = 1; | ||
@@ -31,3 +31,3 @@ this._timeouts = this._originalTimeouts; | ||
RetryOperation.prototype.stop = function() { | ||
RetryOperation.prototype.stop = function stop() { | ||
if (this._timeout) { | ||
@@ -41,3 +41,3 @@ clearTimeout(this._timeout); | ||
RetryOperation.prototype.retry = function(err) { | ||
RetryOperation.prototype.retry = function retry(err) { | ||
if (this._timeout) { | ||
@@ -53,3 +53,3 @@ clearTimeout(this._timeout); | ||
this._errors.push(err); | ||
this._errors.unshift(new Error("RetryOperation timeout occurred")); | ||
this._errors.unshift(new Error('RetryOperation timeout occurred')); | ||
@@ -74,7 +74,7 @@ return false; | ||
const self = this; | ||
const timer = setTimeout(function() { | ||
const timer = setTimeout(function tm1() { | ||
self._attempts++; | ||
if (self._operationTimeoutCb) { | ||
self._timeout = setTimeout(function() { | ||
self._timeout = setTimeout(function tm2() { | ||
self._operationTimeoutCb(self._attempts); | ||
@@ -98,3 +98,3 @@ }, self._operationTimeout); | ||
RetryOperation.prototype.attempt = function(fn, timeoutOps) { | ||
RetryOperation.prototype.attempt = function attempt(fn, timeoutOps) { | ||
this._fn = fn; | ||
@@ -113,3 +113,3 @@ | ||
if (this._operationTimeoutCb) { | ||
this._timeout = setTimeout(function() { | ||
this._timeout = setTimeout(function tm() { | ||
self._operationTimeoutCb(); | ||
@@ -124,23 +124,13 @@ }, self._operationTimeout); | ||
RetryOperation.prototype.try = function(fn) { | ||
console.log("Using RetryOperation.try() is deprecated"); | ||
this.attempt(fn); | ||
}; | ||
RetryOperation.prototype.start = function(fn) { | ||
console.log("Using RetryOperation.start() is deprecated"); | ||
this.attempt(fn); | ||
}; | ||
RetryOperation.prototype.start = RetryOperation.prototype.try; | ||
RetryOperation.prototype.errors = function() { | ||
RetryOperation.prototype.errors = function errorsFn() { | ||
return this._errors; | ||
}; | ||
RetryOperation.prototype.attempts = function() { | ||
RetryOperation.prototype.attempts = function attempsFn() { | ||
return this._attempts; | ||
}; | ||
RetryOperation.prototype.mainError = function() { | ||
RetryOperation.prototype.mainError = function mainErrorFn() { | ||
if (this._errors.length === 0) { | ||
@@ -147,0 +137,0 @@ return null; |
@@ -1,4 +0,4 @@ | ||
const RetryOperation = require("./retry_operation"); | ||
const RetryOperation = require('./retry_operation'); | ||
exports.operation = function(options) { | ||
exports.operation = function operation(options) { | ||
const timeouts = exports.timeouts(options); | ||
@@ -9,7 +9,7 @@ | ||
unref: options && options.unref, | ||
maxRetryTime: options && options.maxRetryTime | ||
maxRetryTime: options && options.maxRetryTime, | ||
}); | ||
}; | ||
exports.timeouts = function(options) { | ||
exports.timeouts = function timeoutsFn(options) { | ||
if (options instanceof Array) { | ||
@@ -24,3 +24,3 @@ return [].concat(options); | ||
maxTimeout: Infinity, | ||
randomize: false | ||
randomize: false, | ||
}; | ||
@@ -34,7 +34,8 @@ if (options) { | ||
if (opts.minTimeout > opts.maxTimeout) { | ||
throw new Error("minTimeout is greater than maxTimeout"); | ||
throw new Error('minTimeout is greater than maxTimeout'); | ||
} | ||
let i = 0; | ||
const timeouts = []; | ||
for (var i = 0; i < opts.retries; i++) { | ||
for (; i < opts.retries; i++) { | ||
timeouts.push(this.createTimeout(i, opts)); | ||
@@ -48,3 +49,3 @@ } | ||
// sort the array numerically ascending | ||
timeouts.sort(function(a, b) { | ||
timeouts.sort(function (a, b) { | ||
return a - b; | ||
@@ -56,3 +57,3 @@ }); | ||
exports.createTimeout = function(attempt, opts) { | ||
exports.createTimeout = function createTimeout(attempt, opts) { | ||
const random = opts.randomize ? Math.random() + 1 : 1; | ||
@@ -68,3 +69,3 @@ | ||
exports.wrap = function(obj, options, methods) { | ||
exports.wrap = function wrap(obj, options, methods) { | ||
if (options instanceof Array) { | ||
@@ -79,3 +80,3 @@ methods = options; | ||
for (const key of Object.keys(obj)) { | ||
if (typeof obj[key] === "function") { | ||
if (typeof obj[key] === 'function') { | ||
methods.push(key); | ||
@@ -91,8 +92,9 @@ } | ||
obj[method] = function retryWrapper(original) { | ||
obj[method] = function retryWrapper(orig) { | ||
const op = exports.operation(options); | ||
// eslint-disable-next-line prefer-rest-params | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
const callback = args.pop(); | ||
args.push(function(err) { | ||
args.push(function fn(err) { | ||
if (op.retry(err)) { | ||
@@ -102,9 +104,11 @@ return; | ||
if (err) { | ||
// eslint-disable-next-line prefer-rest-params | ||
arguments[0] = op.mainError(); | ||
} | ||
// eslint-disable-next-line prefer-rest-params | ||
callback.apply(this, arguments); | ||
}); | ||
op.attempt(function() { | ||
original.apply(obj, args); | ||
op.attempt(() => { | ||
orig.apply(obj, args); | ||
}); | ||
@@ -111,0 +115,0 @@ }.bind(obj, original); |
{ | ||
"name": "async-retry-ng", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Retrying made simple, easy and async", | ||
@@ -10,3 +10,4 @@ "main": "./lib/index.js", | ||
"test-unit": "jest --testTimeout 20000", | ||
"lint:staged": "lint-staged" | ||
"lint:staged": "lint-staged", | ||
"prettier": "prettier --single-quote --write './{src,__tests__}/**/*.js'" | ||
}, | ||
@@ -17,3 +18,3 @@ "files": [ | ||
"license": "MIT", | ||
"repository": "olliv/async-retry-ng", | ||
"repository": "turist-cloud/async-retry-ng", | ||
"pre-commit": "lint:staged", | ||
@@ -23,8 +24,9 @@ "lint-staged": { | ||
"eslint", | ||
"prettier --write --single-quote", | ||
"git add" | ||
"prettier --write --single-quote" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"plugins": ["jest"], | ||
"plugins": [ | ||
"jest" | ||
], | ||
"extends": [ | ||
@@ -36,22 +38,26 @@ "plugin:jest/recommended", | ||
"rules": { | ||
"prefer-arrow-callback": 0, | ||
"no-underscore-dangle": 0 | ||
"no-param-reassign" : 0, | ||
"no-plusplus": 0, | ||
"no-restricted-properties": 0, | ||
"no-restricted-syntax": 0, | ||
"no-underscore-dangle": 0, | ||
"prefer-arrow-callback": 0 | ||
} | ||
}, | ||
"devDependencies": { | ||
"eslint": "6.7.2", | ||
"eslint-config-airbnb": "18.0.1", | ||
"eslint-config-prettier": "6.7.0", | ||
"eslint-plugin-import": "2.19.1", | ||
"eslint-plugin-jest": "23.1.1", | ||
"eslint": "6.8.0", | ||
"eslint-config-airbnb": "18.1.0", | ||
"eslint-config-prettier": "6.10.1", | ||
"eslint-plugin-import": "2.20.1", | ||
"eslint-plugin-jest": "23.8.2", | ||
"eslint-plugin-jsx-a11y": "6.2.3", | ||
"eslint-plugin-react": "7.14.3", | ||
"eslint-plugin-react-hooks": "1.7.0", | ||
"jest": "24.9.0", | ||
"lint-staged": "9.5.0", | ||
"eslint-plugin-react": "7.19.0", | ||
"eslint-plugin-react-hooks": "2.5.1", | ||
"jest": "25.1.0", | ||
"lint-staged": "10.0.8", | ||
"node-fetch": "2.6.0", | ||
"pre-commit": "1.2.2", | ||
"prettier": "1.19.1", | ||
"prettier": "2.0.1", | ||
"then-sleep": "1.0.1" | ||
} | ||
} |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
13407
278