retrier

0.0.1 • Public • Published

Retrier

Simple operation retrier till callback success or max attempts are reached

var retry = require('retrier');
 
var op = function(callback) {
  console.log("I've been called but I won't succed");
  return callback("Error");
}
 
retry(10, op, function(error, response){
  if (error) {
    return console.log("After 10 times I'm here");
  }
  
  return console.log("warning unreachable code")
});

retrier(n, operation, callback);

Will call operation for n times untill it succeeds.

  • n: count to call operation
  • operation: single callback argument function (if you need args, check out async.apply, or function.bind)
  • callback: final callback to be called with response or error if operation failed for n times

PR's are welcomed

Package Sidebar

Install

npm i retrier

Weekly Downloads

3

Version

0.0.1

License

MIT

Last publish

Collaborators

  • tinchogob