simple-retry

0.0.1 • Public • Published

Simple Retry

A simple utility for retrying custom operation until succeed.

Install

$ npm install simple-retry

How to Use

const SimpleRetry = require('../');

let doSomething = (cb) => {
  //do anything you want
  if(error){
    cb(error);
  }else{
    cb(null, result);
  }
};

let sr = new SimpleRetry({fn: doSomething, max_attempts: 10, max_delay: 3000 });

sr.on('error', (error) => console.error(`${error}, ${sr.isReady}`));
sr.on('finish', (result) => console.log(`${result}, ${sr.isReady}`));
sr.retry();

Operation

  • fn: a function for your operation.
  • factor: the exponential factor to calculate the delay time. The current delay time = last delay * factor.
  • max_attempts: the max retry amount.
  • max_delay: the max milliseconds between two retries.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i simple-retry

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • james.y.yang