simple-circuit-breaker
Simple JavaScript (ES6) circuit breaker wrapper for functions returning Promises. No dependencies. Just plain ES6.
Module has configurable grace period, threshold and error message. It simply wraps any function that return promise.
More information about circuit breakers: Circuit Breakers
Usage
Basic usage with defaults
const circuitBreaker = { return } const withCircuitBreaker =
Passing configuration options
Parameters
- asyncFn - Function that we want to guard with circuit breaker Must return a
Promise
- gracePeriodMs - How long do we wait before retrying after switched to CLOSED state
- threshold - How many failures do we need to stop calling backend and start failing immediately - HALF OPEN
- message - This will be the error message in OPEN state
const withCircuitBreaker =
Default values
- gracePeriodMs = 3000
- threshold = 1
- message = 'Functionality disabled due to previous errors.'