a class used to retry some action until some condition is met. the result of the action is passed to the condition function and the end result is returned from the until function (or undefined if the condition is never met and all retry attempts are used up)

Type Parameters

  • T

Hierarchy

  • Retry

Constructors

Properties

_aftCfg: AftConfig
_backOffType: RetryBackOffType
_currentDelay: number
_delay: number
_err: any
_failAction: Func<void, void | PromiseLike<void>>
_maxAttempts: number
_maxDuration: number
_reject: boolean
_result: T
_retryable: Func<Retry<T>, T | PromiseLike<T>>
_success: boolean
_totalAttempts: number
_totalDuration: number

Accessors

  • get isSuccessful(): boolean
  • a boolean indicating if the result of the retryable eventually passed the condition successfully. a value of false indicates that either a maximum duration or number of attempts was reached before success. this can be used if RetryConfig.errorOnFail is set to false

    Returns boolean

  • get totalAttempts(): number
  • the total number of attempts actually executed at the time this is called. this can be used if RetryConfig.errorOnFail is set to false

    Returns number

  • get totalDuration(): number
  • the total amount of time spent calling the retryable until it succeeded or reached the maximum duration or number of attempts. this can be used if RetryConfig.errorOnFail is set to false

    Returns number

Methods

  • tests the passed in result against the specified condition to determine if it succeeds

    Parameters

    • condition: Func<T, boolean | PromiseLike<boolean>>
    • result: T

      a value to test the condition

    Returns Promise<boolean>

    true if the result successfully passes the condition otherwise false

  • allows for specifying a custom condition to determine the success of calling the retryable (default is if the retryable returns a non-null and non-undefined result)

    Parameters

    • condition: Func<T, boolean | PromiseLike<boolean>>

      a function that accepts an argument of type T and returns a boolean result based on a comparison of the argument with an expectation

    Returns Promise<T>

    the current Retry<T> instance

  • the amount of time in milliseconds between attempts

    NOTE

    this is only the starting amount if using a RetryBackOffType of linear or exponential as the value will continually increase on each retry attempt.

    Parameters

    • delay: number

    Returns Retry<T>

    the current Retry<T> instance

    Default

    1
    
  • allows for specifying a function that will be called each time the retryable is called and doesn't succeed (doesn't pass the condition)

    Parameters

    • action: Func<void, void | PromiseLike<void>>

      an Func<void, void | PromiseLike<void>> accepting no arguments and returning nothing

    Returns Retry<T>

    the current Retry<T> instance

  • the maximum number of retry attempts to make before giving up. leaving this unset or set to a value of Infinity means there is no limit

    Parameters

    • attempts: number

    Returns Retry<T>

    the current Retry<T> instance

    Default

    Infinity
    
  • the maximum number of milliseconds to attempt retries. leaving this unset or set to a value of Infinity means there is no duration limit

    Parameters

    • duration: number

    Returns Retry<T>

    the current Retry<T> instance

    Default

    Infinity
    
  • calculates the number of milliseconds to delay between retry attempts using a RetryBackOffType to determine if the value should increase and how if so.

    Ex:

    Retry.calculateBackOffDelay(10, 200, 'linear'); // returns 210
    Retry.calculateBackOffDelay(10, 200, 'exponential'); // returns 400
    Retry.calculateBackOffDelay(10, 200, 'constant'); // returns 10

    Parameters

    • startDelayMs: number

      the number of milliseconds delay at the start

    • currentDelayMs: number

      the number of milliseconds delay last used

    • retryType: RetryBackOffType

      the RetryBackOffType delay type to use

    Returns number

    the number of milliseconds to delay next time

Generated using TypeDoc