0.3.1 • Published 5 years ago

promised-simple-retry v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

promised-simple-retry

Environment

node >= 8.x

Installation

npm install --save promised-simple-retry

Usage

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`
    timeout: 10 * 1000, // maximum execution milliseconds, default `10000`
    interval: 100, // interval milliseconds before execute `task()`, default `3000`
    maxInterval: 20000, // maximum interval, default `20000`,
    delay: 0, // increment to interval.
    when: err => err, // if return `false`, then stop retring.
    delay1st: true, // interval the 1st execution, default `false`
    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

npm i -g mocha
npm run test
0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago