Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (
{
getKey,
failureTimeout = 120000,
failureThreshold = 50,
openTimeout = 60000,
halfOpenThreshold = 5,
minimumFailureCount = 5,
}: Options = {} as Options
): Plugin => {
let getBreaker: (state: ContextState) => CircuitBreaker;
if (isFunction(getKey)) {
const registry = new Map();
getBreaker = (state: ContextState) => {
const key = getKey(state) || '';
let breaker = registry.get(key);
if (!breaker) {
breaker = new CircuitBreaker({
failureTimeout,
failureThreshold,
openTimeout,
halfOpenThreshold,
minimumFailureCount,
});
registry.set(key, breaker);
}