First commit
This commit is contained in:
28
node_modules/backoff/lib/strategy/fibonacci.js
generated
vendored
Normal file
28
node_modules/backoff/lib/strategy/fibonacci.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// 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;
|
||||
Reference in New Issue
Block a user