New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

retryme

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retryme - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.eslintrc

30

index.js

@@ -24,3 +24,3 @@ const Backo = require('backo');

debug('executing action function')
debug('executing action function');
action(once(function next(err) {

@@ -38,2 +38,29 @@ if (!err || err && self.ignore(err)) return fn.apply(this, arguments);

Retryme.prototype.async = function (asyncfn) {
return new Promise((fulfill, reject) => {
debug('Start retries with awaiting async attempt function');
this.attempt(
next => {
return asyncfn()
.then(body => {
next(null, body);
}, err => {
debug('error happens, gonna retry');
next(err);
});
}, (error, body) => {
if (error) {
debug('out of retries, will error out.');
return reject(error);
}
debug('retry succeeds');
fulfill(body);
});
});
};
Retryme.prototype._error = function _error(fn) {

@@ -58,1 +85,2 @@ const error = this.errors.pop();

module.exports = Retryme;

26

package.json
{
"name": "retryme",
"version": "1.0.0",
"description": "",
"version": "1.1.0",
"description": "A more intuitive node-retry which behaves more like async.retry. Utilizes Backo under the hood for backoff.",
"main": "index.js",
"scripts": {
"test": "nyc mocha"
"lint:fix": "eslint -c .eslintrc --fix *.js test/**/*.test.js",
"pretest": "npm run lint:fix",
"test:mocha": "mocha test/*.test.js",
"test": "nyc --reporter=text --reporter=json-summary npm run test:mocha"
},
"repository": {
"type": "git",
"url": "git@github.com:jcrugzz/retryme.git"
},
"keywords": [],
"author": "",
"author": "Jarrett Cruger <jcrugzz@gmail.com>",
"license": "ISC",

@@ -19,6 +26,11 @@ "dependencies": {

"devDependencies": {
"assume": "^1.5.1",
"mocha": "^3.5.0",
"nyc": "^11.1.0"
"assume": "^2.0.1",
"eslint": "^4.19.1",
"eslint-config-godaddy": "^2.1.0",
"eslint-config-godaddy-es5": "^2.1.0",
"eslint-plugin-json": "^1.2.0",
"eslint-plugin-mocha": "^4.12.1",
"mocha": "^5.1.1",
"nyc": "^11.8.0"
}
}

@@ -8,5 +8,10 @@ # retryme

Retryme also supports `async/await` now for retrying async attempt functions.
## Usage
### Regular usage
Here's the example of how to use `retryme` in normal ways.
```js

@@ -28,3 +33,3 @@ var Retryme = require('retryme');

if (err || res.statusCode !== 200) {
return next(err || new Error(`Invalid status code ${res.statusCode}));
return next(err || new Error(`Invalid status code ${res.statusCode}`));
}

@@ -36,3 +41,2 @@ next(null, body);

});
```

@@ -52,3 +56,3 @@

// any 404 error here will no longer be retried due to the function above
return next(err || new Error(`Invalid status code ${res.statusCode}));
return next(err || new Error(`Invalid status code ${res.statusCode}`));
}

@@ -64,2 +68,58 @@ next(null, body);

### `Async/await` Support
Retryme now supports `async/await` by providing `.async` function to retry async attempt functions.
A simple example of how to use it is as follows:
```js
// example of calling the method for async functions returning Promises.
const readFileAsync = require('util').promisify(require('fs').readFile);
const Retryme = require('retryme');
async function main() {
const op = new Retryme({
retries: 2,
min: 50,
max: 10000
}, some_ignore_function_if_exists);
// Wrap a simple file read with retries.
try {
const fileContent = await op.async(() => readFileAsync(__dirname + '/index.js'));
} catch(err) {
console.log('error after 2 attempts');
console.error(err);
}
}
// it supports async functions
async function foo(bad) {
if (bad !== 'hola') return 'bar';
throw Error('what happened');
}
async function main() {
const op = new Retryme();
try {
const result = await op.async(() => foo('hello'));
} catch(err) {
console.error(err);
}
}
// it also supports thenables
async function main() {
await op.async(() => {
return {
then: (f, r) => {
// real functionality happens here
}
};
});
}
```
## test

@@ -72,1 +132,2 @@

[backo]: https://github.com/segmentio/backo
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