Options
All
  • Public
  • Public/Protected
  • All
Menu

Make a function cacheable.

Note: If the result will be null or Promise, result will not be cached Warning: Use only for pure functions.

collboard-modules-sdk

Type parameters

  • TInput

  • TOutput

Hierarchy

  • Destroyable
    • FunctionCache

Implements

  • IDestroyable

Index

Constructors

  • new FunctionCache<TInput, TOutput>(executor: (input: TInput) => TOutput): FunctionCache<TInput, TOutput>
  • Type parameters

    • TInput

    • TOutput

    Parameters

    • executor: (input: TInput) => TOutput
        • (input: TInput): TOutput
        • Parameters

          • input: TInput

          Returns TOutput

    Returns FunctionCache<TInput, TOutput>

Properties

cache: any
executor: any

Accessors

  • get function(): (input: TInput) => TOutput
  • Returns (input: TInput) => TOutput

      • (input: TInput): TOutput
      • Parameters

        • input: TInput

        Returns TOutput

  • get isDestroyed(): boolean
  • Is this object destroyed?

    Returns boolean

Methods

  • addSubdestroyable(...subdestroyable: ITeardownLogic[]): FunctionCache<TInput, TOutput>
  • Binds new registration with itself. This registration/destroyable will be destroyed with this.

    Parameters

    • Rest ...subdestroyable: ITeardownLogic[]

    Returns FunctionCache<TInput, TOutput>

  • checkWhetherNotDestroyed(errorMessage?: string, runBeforeError?: () => void): void
  • Checks, whether the object is not destroyed

    Parameters

    • Optional errorMessage: string

      Message that will replace default one before error

    • Optional runBeforeError: () => void

      Callback runed before error is thrown; typically this can be some logging

        • (): void
        • Returns void

    Returns void

  • destroy(): Promise<void>
  • Returns Promise<void>

  • execute(input: TInput): TOutput
  • Parameters

    • input: TInput

    Returns TOutput

  • isDestroyable(obj: any): obj is IDestroyable
  • Chcek whether the given object is destroyable

    Parameters

    • obj: any

    Returns obj is IDestroyable