From a7345bb16f0a8f38150b2a7ade0fbf8caffd23b0 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 25 Mar 2020 20:49:34 +0100 Subject: [PATCH] propagate measurement reset to reporters, closes #88 --- htdocs/lib/Measurement.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/lib/Measurement.js b/htdocs/lib/Measurement.js index 202070e..e07b196 100644 --- a/htdocs/lib/Measurement.js +++ b/htdocs/lib/Measurement.js @@ -1,4 +1,5 @@ function Measurement() { + this.reporters = []; this.reset(); } @@ -21,10 +22,13 @@ Measurement.prototype.getRate = function() { Measurement.prototype.reset = function() { this.value = 0; this.start = new Date(); + this.reporters.forEach(function(r){ r.reset(); }); }; Measurement.prototype.report = function(range, interval, callback) { - return new Reporter(this, range, interval, callback); + var reporter = new Reporter(this, range, interval, callback); + this.reporters.push(reporter); + return reporter; }; function Reporter(measurement, range, interval, callback) { @@ -59,4 +63,8 @@ Reporter.prototype.report = function(){ var accumulated = newest.value - oldest.value; // we want rate per second, but our time is in milliseconds... compensate by 1000 this.callback(accumulated * 1000 / elapsed); +}; + +Reporter.prototype.reset = function(){ + this.samples = []; }; \ No newline at end of file