UNPKG

@geersch/retry

Version:

Backoff strategies to use when retrying a function after a given delay.

20 lines 818 B
const MEDIAN_INTERVAL_SCALING_FACTOR = 1 / 1.4; export class DecorrelatedJitterBackoffStrategy { baseDelay; constructor({ baseDelay = 100 } = {}) { this.baseDelay = baseDelay; } *getGenerator(maxRetries) { let attempt = 0; let previousValue = 0; while (attempt < maxRetries) { const randomizedAttempt = attempt + Math.random(); const nextValue = Math.pow(2, randomizedAttempt) * Math.tanh(Math.sqrt(4.0 * randomizedAttempt)); const formulaIntrinsicValue = Math.max(0, nextValue - previousValue); previousValue = nextValue; yield formulaIntrinsicValue * MEDIAN_INTERVAL_SCALING_FACTOR * this.baseDelay; attempt += 1; } } } //# sourceMappingURL=decorrelated-jitter.backoff-strategy.js.map