https://github.com/leaf4monkey-npm/retry
https://github.com/leaf4monkey-npm/retry
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/leaf4monkey-npm/retry
- Owner: leaf4monkey-npm
- Created: 2017-04-19T08:58:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-27T08:00:51.000Z (about 9 years ago)
- Last Synced: 2025-02-13T21:05:53.930Z (over 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# promised-simple-retry
## Environment
node >= 4.x
## Installation
```bash
npm install --save promised-simple-retry
```
## Usage
```js
const retry = require('promised-simple-retry');
let task = function () {
// what you want to do.
throw new Error('always wrong.');
};
let options = {
times: 3, // maximum retry times, default `3`
delay: 100, // delay milliseconds before execute `task()`, default `0`
delay1st: true, // delay the 1st execution, default `false`
timeout: 10 * 1000, // maximum execution milliseconds, default `0`
debug: false
};
retry(task, options).then(function (res) {
console.log('success');
}).catch(function (err) {
console.log('failed');
console.log(`tried ${err.tried} times.`);
console.log(`cost ${err.cost} ms in total.`);
});
```
## Test
```bash
npm i -g mocha
npm run test
```