linx-simulator2/node_modules/backoff/lib/strategy/fibonacci.js
2019-09-18 11:11:16 +03:00

29 lines
855 B
JavaScript

// Copyright (c) 2012 Mathieu Turcotte
// Licensed under the MIT license.
var util = require('util');
var BackoffStrategy = require('./strategy');
// Fibonacci backoff strategy.
function FibonacciBackoffStrategy(options) {
BackoffStrategy.call(this, options);
this.backoffDelay_ = 0;
this.nextBackoffDelay_ = this.getInitialDelay();
}
util.inherits(FibonacciBackoffStrategy, BackoffStrategy);
FibonacciBackoffStrategy.prototype.next_ = function() {
var backoffDelay = Math.min(this.nextBackoffDelay_, this.getMaxDelay());
this.nextBackoffDelay_ += this.backoffDelay_;
this.backoffDelay_ = backoffDelay;
return backoffDelay;
};
FibonacciBackoffStrategy.prototype.reset_ = function() {
this.nextBackoffDelay_ = this.getInitialDelay();
this.backoffDelay_ = 0;
};
module.exports = FibonacciBackoffStrategy;