Ohm-Management - Projektarbeit B-ME
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.

fibonacci.js 855B

12345678910111213141516171819202122232425262728
  1. // Copyright (c) 2012 Mathieu Turcotte
  2. // Licensed under the MIT license.
  3. var util = require('util');
  4. var BackoffStrategy = require('./strategy');
  5. // Fibonacci backoff strategy.
  6. function FibonacciBackoffStrategy(options) {
  7. BackoffStrategy.call(this, options);
  8. this.backoffDelay_ = 0;
  9. this.nextBackoffDelay_ = this.getInitialDelay();
  10. }
  11. util.inherits(FibonacciBackoffStrategy, BackoffStrategy);
  12. FibonacciBackoffStrategy.prototype.next_ = function() {
  13. var backoffDelay = Math.min(this.nextBackoffDelay_, this.getMaxDelay());
  14. this.nextBackoffDelay_ += this.backoffDelay_;
  15. this.backoffDelay_ = backoffDelay;
  16. return backoffDelay;
  17. };
  18. FibonacciBackoffStrategy.prototype.reset_ = function() {
  19. this.nextBackoffDelay_ = this.getInitialDelay();
  20. this.backoffDelay_ = 0;
  21. };
  22. module.exports = FibonacciBackoffStrategy;