back-off

4.3.0 • Public • Published

Back-Off

npm version Build Status Coverage Status

Circuit Breaker design pattern for JavaScript

circuit breaker

This module let's you use the Circuit Breaker pattern and call a function multiple times. In addition you can specify a delay to be applied between attempts as well as extending the delay as attempts are made.

Async/Await

const BackOff = require('back-off');
const backoff = new BackOff({
    times: 5, //number of times method should be called
    delay: 50, //delay in milliseconds between calls
    backoff: true // if the delay should be doubled between execution attempts
});
try {
  const result = await backoff.execute(asyncTask);
} catch (error) {
  //do something with the final error
}
 

Promise

const BackOff = require('back-off');
const backoff = new BackOff({
  times: 5, //number of times method should be called
  delay: 50, //delay in milliseconds between calls
  backoff: true // if the delay should be doubled between execution attempts
});
 
backoff.execute(() => {
  //do something here that may fail
})
.then(()=> {
  // do something else
})
.catch(() => {
  //attempts failed
});
 

The tests show the module in action.

Package Sidebar

Install

npm i back-off

Weekly Downloads

4,350

Version

4.3.0

License

Unlicense

Unpacked Size

9.42 kB

Total Files

4

Last publish

Collaborators

  • kev_nz