Options
All
  • Public
  • Public/Protected
  • All
Menu

@proficient/util - v0.2.0

Index

Type aliases

RetriableResult<T>: { errors: unknown[]; trialCount: number } & ({ hasSucceeded: true; value: Awaited<T> } | { hasSucceeded: false })

Type parameters

  • T

RetriableVersionOf<F>: (...args: Parameters<F>) => Promise<RetriableResult<ReturnType<F>>>

Type parameters

  • F: (...args: any[]) => any

Type declaration

Functions

  • Creates a retriable version of a given function, which, when invoked, is continuously retried according to the specified retry config until it succeeds. The new function returns a Promise that resolves when the original function succeeds or maxTrialCount is reached.

    Type parameters

    • F: (...args: any[]) => any

    Parameters

    • originalFunc: F

      A function whose retriable version to create.

    • retryConfig: RetryConfig

      The configuration with which the retriable version of the original function will be created.

    Returns RetriableVersionOf<F>

    A an asynchronous function that returns a Promise resolving to an object containing the details of the retry process including a boolean indicating whether it has succeeded or not. This newly created function does not throw.

  • registerInterval(callback: () => void | Promise<void>, duration: number): () => Promise<void>
  • registerInterval(callback: () => void | Promise<void>, getDuration: () => number): () => Promise<void>
  • Registers an async callback that keeps running in the background until it is unregistered. Waits for the callback Promise to resolve and sleeps for an additional duration ms and invokes the callback again.

    Parameters

    • callback: () => void | Promise<void>

      An asynchronous function that will keep running in the background.

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

    • duration: number

      The amount of time (in ms) to sleep after the callback Promise resolves before invoking the callback again.

    Returns () => Promise<void>

    A an asynchronous function that unregisters the callback. The function returns a Promise that resolves when the very last interval finishes processing.

      • (): Promise<void>
      • Registers an async callback that keeps running in the background until it is unregistered. Waits for the callback Promise to resolve and sleeps for an additional duration ms and invokes the callback again.

        Returns Promise<void>

        A an asynchronous function that unregisters the callback. The function returns a Promise that resolves when the very last interval finishes processing.

  • Registers an async callback that keeps running in the background until it is unregistered. Waits for the callback Promise to resolve and sleeps for an additional duration ms and invokes the callback again.

    Parameters

    • callback: () => void | Promise<void>

      An asynchronous function that will keep running in the background.

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

    • getDuration: () => number

      A function that returns the amount of time (in ms) to sleep after the callback Promise resolves before invoking the callback again.

        • (): number
        • Returns number

    Returns () => Promise<void>

    A an asynchronous function that unregisters the callback. The function returns a Promise that resolves when the very last interval finishes processing.

      • (): Promise<void>
      • Registers an async callback that keeps running in the background until it is unregistered. Waits for the callback Promise to resolve and sleeps for an additional duration ms and invokes the callback again.

        Returns Promise<void>

        A an asynchronous function that unregisters the callback. The function returns a Promise that resolves when the very last interval finishes processing.

  • sleep(duration: number): Promise<void>
  • Sleeps for a specified number of milliseconds.

    Parameters

    • duration: number

      Duration to sleep (in ms).

    Returns Promise<void>

    A Promise that resolves after the specified duration.

Generated using TypeDoc