Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fibonacci and exponential backoff for Node.js
JavaScript CSS

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
tests
.gitignore
.travis.yml
LICENSE
README.md
backoff.js
package.json

README.md

Exponential backoff implementation for Node.js

An exponential backoff implementation for Node.js.

Installation

npm install backoff

Usage

The Backoff object inherits from EventEmitter. One can listen for backoff completion by listening for 'backoff' events. Registered handlers will be called with the current backoff number and delay.

var Backoff = require('backoff');

var backoff = new Backoff();

backoff.on('backoff', function(number, delay) {
    // Retry operation...
    backoff.backoff();
});

backoff.backoff();

It's also possible to reset 'Backoff' instance. Once reset, a 'Backoff' instance can be reused. On reset, the 'reset' event will be emitted.

var Backoff = require('backoff');

var backoff = new Backoff();

backoff.on('backoff', function(number, delay) {
    backoff.backoff();
});

backoff.on('reset', function() {
    console.log('reset');
});

backoff.backoff();

setTimeout(function() {
    backoff.reset();
}, 5000);
Something went wrong with that request. Please try again.