delay.base.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var jitter_factory_1 = require("../jitter/jitter.factory");
  4. var Delay = /** @class */ (function () {
  5. function Delay(options) {
  6. this.options = options;
  7. this.attempt = 0;
  8. }
  9. Delay.prototype.apply = function () {
  10. var _this = this;
  11. return new Promise(function (resolve) { return setTimeout(resolve, _this.jitteredDelay); });
  12. };
  13. Delay.prototype.setAttemptNumber = function (attempt) {
  14. this.attempt = attempt;
  15. };
  16. Object.defineProperty(Delay.prototype, "jitteredDelay", {
  17. get: function () {
  18. var jitter = jitter_factory_1.JitterFactory(this.options);
  19. return jitter(this.delay);
  20. },
  21. enumerable: true,
  22. configurable: true
  23. });
  24. Object.defineProperty(Delay.prototype, "delay", {
  25. get: function () {
  26. var constant = this.options.startingDelay;
  27. var base = this.options.timeMultiple;
  28. var power = this.numOfDelayedAttempts;
  29. var delay = constant * Math.pow(base, power);
  30. return Math.min(delay, this.options.maxDelay);
  31. },
  32. enumerable: true,
  33. configurable: true
  34. });
  35. Object.defineProperty(Delay.prototype, "numOfDelayedAttempts", {
  36. get: function () {
  37. return this.attempt;
  38. },
  39. enumerable: true,
  40. configurable: true
  41. });
  42. return Delay;
  43. }());
  44. exports.Delay = Delay;
  45. //# sourceMappingURL=delay.base.js.map