async-retry
Advanced tools
Comparing version 1.2.1 to 1.2.2
// Packages | ||
const retrier = require('retry') | ||
var retrier = require('retry'); | ||
module.exports = (fn, opts) => { | ||
opts = opts || {} | ||
function retry(fn, opts) { | ||
function run(resolve, reject) { | ||
var options = opts || {}; | ||
var op = retrier.operation(options); | ||
return new Promise((resolve, reject) => { | ||
const op = retrier.operation(opts) | ||
// We allow the user to abort retrying | ||
@@ -14,30 +13,43 @@ // this makes sense in the cases where | ||
// would be futile (e.g.: auth errors) | ||
const bail = err => reject(err || new Error('Aborted')) | ||
const onError = (err, num) => { | ||
function bail(err) { | ||
reject(err || new Error('Aborted')); | ||
} | ||
function onError(err, num) { | ||
if (err.bail) { | ||
return bail(err) | ||
bail(err); | ||
return; | ||
} | ||
if (!op.retry(err)) { | ||
reject(op.mainError()) | ||
} else if (opts.onRetry) { | ||
opts.onRetry(err, num) | ||
reject(op.mainError()); | ||
} else if (options.onRetry) { | ||
options.onRetry(err, num); | ||
} | ||
} | ||
op.attempt(num => { | ||
let val | ||
function runAttempt(num) { | ||
var val; | ||
try { | ||
val = fn(bail, num) | ||
val = fn(bail, num); | ||
} catch (err) { | ||
return onError(err, num) | ||
onError(err, num); | ||
return; | ||
} | ||
Promise.resolve(val) | ||
.then(resolve) | ||
.catch(err => { | ||
onError(err, num) | ||
}) | ||
}) | ||
}) | ||
.catch(function catchIt(err) { | ||
onError(err, num); | ||
}); | ||
} | ||
op.attempt(runAttempt); | ||
} | ||
return new Promise(run); | ||
} | ||
module.exports = retry; |
{ | ||
"name": "async-retry", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Retrying made simple, easy and async", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "yarn run test-lint && yarn run test-unit", | ||
"test-lint": "eslint .", | ||
"test-unit": "ava", | ||
"lint:staged": "lint-staged" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"license": "MIT", | ||
@@ -14,19 +20,37 @@ "repository": "zeit/async-retry", | ||
}, | ||
"xo": { | ||
"esnext": true, | ||
"space": true, | ||
"semicolon": false, | ||
"ignores": [ | ||
"examples/**/*" | ||
"dependencies": { | ||
"retry": "0.12.0" | ||
}, | ||
"pre-commit": "lint:staged", | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint", | ||
"prettier --write --single-quote", | ||
"git add" | ||
] | ||
}, | ||
"dependencies": { | ||
"retry": "0.10.1" | ||
"eslintConfig": { | ||
"extends": [ | ||
"airbnb", | ||
"prettier" | ||
], | ||
"rules": { | ||
"no-var": 0, | ||
"prefer-arrow-callback": 0 | ||
} | ||
}, | ||
"devDependencies": { | ||
"ava": "0.25.0", | ||
"node-fetch": "2.0.0", | ||
"then-sleep": "1.0.1", | ||
"xo": "0.20.3" | ||
"eslint": "5.5.0", | ||
"eslint-config-airbnb": "17.1.0", | ||
"eslint-config-prettier": "3.0.1", | ||
"eslint-plugin-import": "2.14.0", | ||
"eslint-plugin-jsx-a11y": "6.1.1", | ||
"eslint-plugin-react": "7.11.1", | ||
"lint-staged": "7.2.2", | ||
"node-fetch": "2.2.0", | ||
"pre-commit": "1.2.2", | ||
"prettier": "1.14.2", | ||
"then-sleep": "1.0.1" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
1
5376
12
4
43
+ Addedretry@0.12.0(transitive)
- Removedretry@0.10.1(transitive)
Updatedretry@0.12.0