Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Retry.js 581B

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. }