|
12345678910111213141516171819202122232425262728 |
- // 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;
|