@newdash/newdash
Version:
javascript/typescript utility library
54 lines (53 loc) • 1.61 kB
TypeScript
import { GeneralFunction } from "../types";
import { fallbackCache } from "./cache";
import { circuit } from "./circuit";
import { fallbackRetry } from "./retry";
interface RecommendFallbackCreatorOptions {
/**
* LRUCache size for circuit & cache
*/
cacheSize?: number;
/**
* circuit opening duration after failure, in milliseconds, default is 10000 (10 seconds)
*/
circuitOpenDuration?: number;
/**
* retry times after failure happened, **INTEGER** please
*/
retryMaximumTime?: number;
/**
* the duration between each time retry, in milliseconds
*/
retryInterval?: number;
}
/**
* recommend fallback policy
*
* `cache <- circuit <- retry <- runner`
*
* when error happened from `runner`, `retry` it firstly
*
* if `retry` finally failed, the `circuit breaker` will open,
* later requests in a **duration** will not be executed, and just throw the `temp not available error`
*
* if the `circuit` is open, `cache` will catch the error, and try to get value from previous successful `cache`
*
* if there is no successful cache before, throw the original error (maybe wrapper with [[TemporaryUnAvailableError]]) directly
*
* @since 5.15.0
* @category Fallback
* @param runner
*/
export declare function recommend<T extends GeneralFunction>(runner: T, options?: RecommendFallbackCreatorOptions): T;
/**
* fallback namespace
*
* @since 5.15.0
*/
export declare const fallback: {
cache: typeof fallbackCache;
retry: typeof fallbackRetry;
circuit: typeof circuit;
recommend: typeof recommend;
};
export {};