How to use the @tinkoff/utils/is/function function in @tinkoff/utils

To help you get started, we’ve selected a few @tinkoff/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TinkoffCreditSystems / tinkoff-request / packages / plugin-circuit-breaker / src / circuit-breaker.ts View on Github external
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);
            }