2014-08-09 17:38:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-04-12 12:55:20 +00:00
|
|
|
function request_delay_balancer(refresh_period) {
|
|
|
|
this.balance_to = refresh_period;
|
|
|
|
this.request_t = 0;
|
|
|
|
this.finished_t = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-09 17:38:46 +00:00
|
|
|
request_delay_balancer.prototype.requested = function () {
|
2014-04-12 12:55:20 +00:00
|
|
|
this.request_t = millitime();
|
|
|
|
};
|
|
|
|
|
2014-08-09 17:38:46 +00:00
|
|
|
request_delay_balancer.prototype.finished = function () {
|
2014-04-12 12:55:20 +00:00
|
|
|
this.finished_t = millitime();
|
|
|
|
};
|
|
|
|
|
2014-08-09 17:38:46 +00:00
|
|
|
request_delay_balancer.prototype.estimate = function () {
|
2014-04-12 12:55:20 +00:00
|
|
|
var estimate = this.balance_to - (this.finished_t - this.request_t);
|
|
|
|
return (estimate > 0) ? estimate : 0;
|
|
|
|
};
|