From b14d26d5305905067ae2b8d1293b5939ab93608e Mon Sep 17 00:00:00 2001 From: cTn Date: Sat, 12 Apr 2014 14:55:20 +0200 Subject: [PATCH] initial implementation of request delay balancer --- js/request_balancer.js | 18 ++++++++++++++++++ main.html | 1 + main.js | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 js/request_balancer.js diff --git a/js/request_balancer.js b/js/request_balancer.js new file mode 100644 index 00000000..490ddee7 --- /dev/null +++ b/js/request_balancer.js @@ -0,0 +1,18 @@ +function request_delay_balancer(refresh_period) { + this.balance_to = refresh_period; + this.request_t = 0; + this.finished_t = 0; +} + +request_delay_balancer.prototype.requested = function() { + this.request_t = millitime(); +}; + +request_delay_balancer.prototype.finished = function() { + this.finished_t = millitime(); +}; + +request_delay_balancer.prototype.estimate = function() { + var estimate = this.balance_to - (this.finished_t - this.request_t); + return (estimate > 0) ? estimate : 0; +}; \ No newline at end of file diff --git a/main.html b/main.html index 5a407653..46f8c030 100644 --- a/main.html +++ b/main.html @@ -26,6 +26,7 @@ + diff --git a/main.js b/main.js index 2873f35d..4c410633 100644 --- a/main.js +++ b/main.js @@ -181,6 +181,12 @@ function microtime() { return now; } +function millitime() { + var now = new Date().getTime(); + + return now; +} + /* function add_custom_spinners() { var spinner_element = '
';