JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1160144
  • Score
    100M100P100Q178046F

Exponential backoff implementation.

Package Exports

  • backoff

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (backoff) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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);