Socket
Socket
Sign inDemoInstall

p-retry

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-retry - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

index.d.ts

41

index.js

@@ -21,3 +21,3 @@ 'use strict';

function decorateErrorWithCounts(error, attemptNumber, options) {
const decorateErrorWithCounts = (error, attemptNumber, options) => {
// Minus 1 from attemptNumber because the first attempt does not count as a retry

@@ -28,17 +28,23 @@ const retriesLeft = options.retries - (attemptNumber - 1);

error.retriesLeft = retriesLeft;
return error;
}
};
module.exports = (input, options) => new Promise((resolve, reject) => {
options = Object.assign({
const pRetry = (input, options) => new Promise((resolve, reject) => {
options = {
onFailedAttempt: () => {},
retries: 10
}, options);
retries: 10,
...options
};
const operation = retry.operation(options);
operation.attempt(attemptNumber => Promise.resolve(attemptNumber)
.then(input)
.then(resolve, error => {
operation.attempt(async attemptNumber => {
try {
resolve(await input(attemptNumber));
} catch (error) {
if (!(error instanceof Error)) {
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
return;
}
if (error instanceof AbortError) {

@@ -50,14 +56,17 @@ operation.stop();

reject(error);
} else if (operation.retry(error)) {
decorateErrorWithCounts(error, attemptNumber, options);
options.onFailedAttempt(error);
} else {
decorateErrorWithCounts(error, attemptNumber, options);
options.onFailedAttempt(error);
reject(operation.mainError());
if (!operation.retry(error)) {
reject(operation.mainError());
}
}
})
);
}
});
});
module.exports = pRetry;
module.exports.default = pRetry;
module.exports.AbortError = AbortError;
{
"name": "p-retry",
"version": "3.0.1",
"version": "4.0.0",
"description": "Retry a promise-returning or async function",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -42,9 +43,11 @@ "keywords": [

"dependencies": {
"@types/retry": "^0.12.0",
"retry": "^0.12.0"
},
"devDependencies": {
"ava": "^1.1.0",
"ava": "^1.3.1",
"delay": "^4.1.0",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc