Home Manual Reference Source Test

src/backoff/constant.js

  1. /**
  2. * Constant Backoff
  3. */
  4. export class ConstantBackoff {
  5. /**
  6. * Creates a new constant backoff strategy.
  7. * @param options
  8. */
  9. constructor(options) {
  10. this.options = {
  11. delay: Math.max(options.delay, 0),
  12. jitter: Math.min(Math.max(options.jitter || 0, 0), 1),
  13. };
  14. }
  15. /**
  16. * @inheritDoc
  17. */
  18. getDelay() {
  19. let delay = this.options.delay;
  20. if (this.options.jitter > 0) {
  21. const min = delay * (1 - this.options.jitter);
  22. const max = delay * (1 + this.options.jitter);
  23. delay = Math.random() * (max - min) + min;
  24. }
  25. return delay;
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. next() {
  31. return this;
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. reset() {
  37. return this;
  38. }
  39. }