@geersch/retry
Version:
Backoff strategies to use when retrying a function after a given delay.
22 lines • 667 B
JavaScript
export class FibonacciBackoffStrategy {
baseDelay;
prevDelay;
currentDelay;
constructor({ baseDelay = 100 } = {}) {
this.baseDelay = baseDelay;
this.prevDelay = 0;
this.currentDelay = 1;
}
*getGenerator(maxRetries) {
let attempt = 0;
while (attempt < maxRetries) {
const nextDelay = this.baseDelay * this.currentDelay;
yield nextDelay;
const sum = this.prevDelay + this.currentDelay;
this.prevDelay = this.currentDelay;
this.currentDelay = sum;
attempt += 1;
}
}
}
//# sourceMappingURL=fibonacci.backoff-strategy.js.map