Variable fallbackConst

fallback: {
    cache: (<T>(runner, cacheSize?) => T);
    circuit: (<T>(runner, openDuration?, cacheSize?) => T);
    recommend: (<T>(runner, options?) => T);
    retry: (<T>(runner, maxRetryNumber?, retryAfterMSecond?) => T);
} = ...

fallback namespace

Type declaration

  • cache: (<T>(runner, cacheSize?) => T)
      • <T>(runner, cacheSize?): T
      • fallback to cache, if runner throw error, will try to return the latest cached value

        Type Parameters

        Parameters

        • runner: T
        • cacheSize: number = 1024

          the maximum number cache item (different parameters)

        Returns T

        Since

        5.15.0

  • circuit: (<T>(runner, openDuration?, cacheSize?) => T)
      • <T>(runner, openDuration?, cacheSize?): T
      • fallback to circuit

        will directly raise error [[TemporaryUnAvailableError]] when some error happened before in duration

        Type Parameters

        Parameters

        • runner: T
        • openDuration: number = ...

          default is 10000 (10 seconds)

        • cacheSize: number = 1024

          the timer & error cache size, default is 1024

        Returns T

  • recommend: (<T>(runner, options?) => T)
      • <T>(runner, options?): T
      • 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

        Type Parameters

        Parameters

        • runner: T
        • options: RecommendFallbackCreatorOptions = {}

        Returns T

        Since

        5.15.0

  • retry: (<T>(runner, maxRetryNumber?, retryAfterMSecond?) => T)
      • <T>(runner, maxRetryNumber?, retryAfterMSecond?): T
      • fallback to retry

        Type Parameters

        Parameters

        • runner: T

          async function, return promise

        • maxRetryNumber: number = 3

          the maximum number of times a runner should retry, default is 3

        • Optional retryAfterMSecond: number

          the wait milliseconds before retry

          Optional

        Returns T

        Since

        5.15.0

Since

5.15.0