Name: js-handler/node_modules/restify/node_modules/backoff/lib/strategy/exponential.js 
1:
/*
2:
 * Copyright (c) 2012 Mathieu Turcotte
3:
 * Licensed under the MIT license.
4:
 */
5:
 
6:
var util = require('util');
7:
 
8:
var BackoffStrategy = require('./strategy');
9:
 
10:
/**
11:
 * Exponential backoff strategy.
12:
 * @extends BackoffStrategy
13:
 */
14:
function ExponentialBackoffStrategy(options) {
15:
    BackoffStrategy.call(this, options);
16:
    this.backoffDelay_ = 0;
17:
    this.nextBackoffDelay_ = this.getInitialDelay();
18:
}
19:
util.inherits(ExponentialBackoffStrategy, BackoffStrategy);
20:
 
21:
/** @inheritDoc */
22:
ExponentialBackoffStrategy.prototype.next_ = function() {
23:
    this.backoffDelay_ = Math.min(this.nextBackoffDelay_, this.getMaxDelay());
24:
    this.nextBackoffDelay_ = this.backoffDelay_ * 2;
25:
    return this.backoffDelay_;
26:
};
27:
 
28:
/** @inheritDoc */
29:
ExponentialBackoffStrategy.prototype.reset_ = function() {
30:
    this.backoffDelay_ = 0;
31:
    this.nextBackoffDelay_ = this.getInitialDelay();
32:
};
33:
 
34:
module.exports = ExponentialBackoffStrategy;