Options
All
  • Public
  • Public/Protected
  • All
Menu

Module fallback

Index

Variables

Functions Fallback

Variables

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

fallback namespace

since

5.15.0

Type declaration

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

        since

        5.15.0

        Type parameters

        • T

        Parameters

        • runner: T
        • cacheSize: number = 1024

          the maximum number cache item (different parameters)

        Returns T

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

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

        Type parameters

        • T

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

        since

        5.15.0

        Type parameters

        Parameters

        • runner: T
        • options: RecommendFallbackCreatorOptions = {}

        Returns T

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

        since

        5.15.0

        Type parameters

        • T

        Parameters

        • runner: T

          async function, return promise

        • maxRetryNumber: number = 3

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

        • Optional retryAfterSeconds: number

        Returns T

Fallback Functions

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

    since

    5.15.0

    Type parameters

    Parameters

    • runner: T
    • options: RecommendFallbackCreatorOptions = {}

    Returns T