
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
ckt-breaker
Advanced tools
Tiny circuit breaker implementation. Wrapped service must return Promise.
$ npm install --save ckt-breaker
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
Type: function
A promise returning function
Type: integer
Default: 10000
Time in ms after which to retry hitting fn
Type: integer
Default: 0
Time in ms to timeout fn if fn takes longer than that. By default this is disabled (0).
Type: integer
Default: 10
No of errors in maxTime
time to occur before breaking the circuit
Type: integer
Default: 1000
Time Frame to consider maxError no of error to break the circuit
Type: function
Default: () => Promise.reject(new Error('Service Currently unavailable')
Fallback function to call when circuit is broken
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
Fired when circuit is opened
Fired when circuit is closed
MIT © Nikhil Srivastava
FAQs
Tiny circuit breaker implementation in js with zero deps
The npm package ckt-breaker receives a total of 0 weekly downloads. As such, ckt-breaker popularity was classified as not popular.
We found that ckt-breaker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.