Function retry

  • Utility to re-run the given promise function until it resolves or until the number of tries was exceeded.

    Example

    // try up to four times with 2s delay between each try
    const model = await retry(Model.find(1), 4, 2000);

    Type Parameters

    • T

    Parameters

    • fn: (() => Promise<T>)

      The function returning a promise to be called.

        • (): Promise<T>
        • Returns Promise<T>

    • Optional maxRetries: number[]

      The number of times the function should be retried. If an array is given, it will be used as the wait time between each try.

    • Optional timeout: undefined

      The wait time between attempts in milliseconds. If 0, it will not wait. If a function, it will be called with the number of retries left.

    • Optional errorCheck: ((err) => boolean)

      A function returning a boolean depending on if error should be retried.

        • (err): boolean
        • Parameters

          • err: unknown

          Returns boolean

    Returns Promise<T>

  • Type Parameters

    • T

    Parameters

    • fn: (() => Promise<T>)
        • (): Promise<T>
        • Returns Promise<T>

    • Optional maxRetries: number
    • Optional timeout: number | ((currentAttemptCount) => number)
    • Optional errorCheck: ((err) => boolean)
        • (err): boolean
        • Parameters

          • err: unknown

          Returns boolean

    Returns Promise<T>

Generated using TypeDoc