You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314
  1. /**
  2. * Gets next timeout using the full jitter pattern.
  3. *
  4. * NOTE that there are no checks for argument correctness, so either do the math or use defaults.
  5. *
  6. * @param {number} retry - The retry number.
  7. * @param {number} minDelay - The minimal delay in milliseconds.
  8. * @param {number} base - The exponent base.
  9. * @returns {number} - The amount of waiting before trying another time given in milliseconds.
  10. * @private
  11. */
  12. export function getJitterDelay(retry, minDelay = 500, base = 2) {
  13. return Math.floor((Math.random() * ((Math.pow(base, retry) * 1000) - minDelay)) + minDelay);
  14. }