Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ckt-breaker

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ckt-breaker

Tiny circuit breaker implementation in js with zero deps

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ckt-breaker Build Status Coverage Status

Tiny circuit breaker implementation. Wrapped service must return Promise.

Requirements

  • node v6+
  • npm 3+

Install

$ npm install --save ckt-breaker

Usage

const cktBreaker = require('ckt-breaker');
// Function that hits some service 
const fn = () => Promise.reject('I got nothing');

const ckt = cktBreaker(fn, {
	retry: 10000, // time in ms after which to retry hitting fn
	timeout: 1000, // time in ms to timeout if fn takes longer than that
	maxError: 10, // Max no of errors
	maxTime: 1000, // time in ms in which maxError occurs
	fallback: () => Promise.reject(new Error('Service Currently unavailable')),
});

ckt.fire('hello world') // Safe doesn't overload the remote service

API

cktBreaker(fn, {options})

fn

Type: function

A promise returning function

options
retry

Type: integer
Default: 10000

Time in ms after which to retry hitting fn

timeout

Type: integer
Default: 0

Time in ms to timeout fn if fn takes longer than that. By default this is disabled (0).

maxError

Type: integer
Default: 10

No of errors in maxTime time to occur before breaking the circuit

maxTime

Type: integer
Default: 1000

Time Frame to consider maxError no of error to break the circuit

fallback

Type: function
Default: () => Promise.reject(new Error('Service Currently unavailable')

Fallback function to call when circuit is broken

Methods

fire
const ckt = cktBreaker(fn); 
ckt.fire([1,2,3]) // Any args taken by fn;

Function that runs wrapped fn and passes over arguments given to it

Events

open

Fired when circuit is opened

closed

Fired when circuit is closed

License

MIT © Nikhil Srivastava

Keywords

FAQs

Package last updated on 07 May 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc