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.

ExponentialBackoff.js 797B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const DEFAULT_MIN = 100;
  4. const DEFAULT_MAX = 1000;
  5. class ExponentialBackoff {
  6. constructor(opts = {}) {
  7. var _a, _b;
  8. this.factor = 2;
  9. this.numAttempts = 0;
  10. this.ms = (_a = opts.min) !== null && _a !== void 0 ? _a : DEFAULT_MIN;
  11. this.max = (_b = opts.max) !== null && _b !== void 0 ? _b : DEFAULT_MAX;
  12. }
  13. get attempts() {
  14. return this.numAttempts;
  15. }
  16. duration() {
  17. const ms = this.ms * Math.pow(this.factor, this.numAttempts);
  18. this.numAttempts += 1;
  19. return Math.floor(Math.min(ms, this.max));
  20. }
  21. reset() {
  22. this.numAttempts = 0;
  23. }
  24. }
  25. exports.default = ExponentialBackoff;
  26. //# sourceMappingURL=ExponentialBackoff.js.map