Handle callback retries with incremental backoff and timeout support.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.bumpedrc
.editorconfig
.gitattributes
.gitignore
.npmignore
.npmrc
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
index.js
package.json

README.md

retry-backoff

Last version Build Status Dependency status Dev Dependencies Status NPM Status Donate

Handle callback retries with incremental backoff and timeout support.

Install

$ npm install retry-backoff --save

Usage

const createRetryBackoff = require('retry-backoff')

function fn (cb) {
  setTimeout(function () {
    return cb(null, {foo: 'bar'})
  }, 1000)
}

const retryBackoff = createRetryBackoff()

retryBackoff(fn, function (err, result) {
  if (err) throw err
  retryBackoff.reset()
  console.log(result) // => {foo: 'bar'}
})

If you need to see low level logs, enable it using DEBUG=retry-backoff.

API

retryBackoff([options])

Creates a backoff function.

options

timeout

Type: number
Default: 30000

Setup the time (in milliseconds) after consider a request timeout.

retries

Type: number
Default: 3

Number of retries before throw a final error.

backoff

Type: function
Default: 1000 * Math.pow(2, retry) + Math.random() * 100

The method uses for calculate the incremental delay between sucesive calls, where retry is attempt number (starts from 0).

.reset

Restart the retries counter.

License

MIT © AudienseCo