Get time until next attempt using exponential backoff Defaults to 1.35^attempt seconds. This results in about four minutes total time for 15 attempts. The first attempt always runs immediately

Constructors

  • Exponential backoff starting at a specified time Defaults to 1.35^attempt seconds. This results in about four minutes total time for 15 attempts.

    Parameters

    • maxAttempts: number = 15

      attempt at which to stop (exclusive, starting at 0)

    • rate: number = 1.35
    • interval: number = 1000
    • startTime: number = ...

      unix timestamp in ms

    Returns ExponentialBackoff

Properties

attempt: number
lastSleepTime: number
maxAttempts: number
startTime: number

Methods

  • Get the delay until next attempt, assuming the last attempt was the previous index. Time elapsed since the last call is subtracted from the delay. Attempt 0 is always immediate.

    Returns number

  • Gets the total time in milliseconds this exponential backoff will take, if all attempts are used.

    Returns number

  • Returns true, if there are attempts left

    Returns boolean

  • Wait for the next attempt. Time elapsed since the last call is subtracted from the delay. Attempt 0 is always immediate. Increases internal attempt counter

    Returns Promise<boolean>

    true, if waited for the time of the current step, false if the maxAttempt was reached