Socket
Socket
Sign inDemoInstall

back-off

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    back-off

Circuit Breaker pattern in js


Version published
Weekly downloads
4.3K
decreased by-0.14%
Maintainers
1
Install size
34.0 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 01 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc