propagate measurement reset to reporters, closes #88
This commit is contained in:
parent
0bffc2b3dd
commit
a7345bb16f
@ -1,4 +1,5 @@
|
|||||||
function Measurement() {
|
function Measurement() {
|
||||||
|
this.reporters = [];
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,10 +22,13 @@ Measurement.prototype.getRate = function() {
|
|||||||
Measurement.prototype.reset = function() {
|
Measurement.prototype.reset = function() {
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
this.start = new Date();
|
this.start = new Date();
|
||||||
|
this.reporters.forEach(function(r){ r.reset(); });
|
||||||
};
|
};
|
||||||
|
|
||||||
Measurement.prototype.report = function(range, interval, callback) {
|
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) {
|
function Reporter(measurement, range, interval, callback) {
|
||||||
@ -59,4 +63,8 @@ Reporter.prototype.report = function(){
|
|||||||
var accumulated = newest.value - oldest.value;
|
var accumulated = newest.value - oldest.value;
|
||||||
// we want rate per second, but our time is in milliseconds... compensate by 1000
|
// we want rate per second, but our time is in milliseconds... compensate by 1000
|
||||||
this.callback(accumulated * 1000 / elapsed);
|
this.callback(accumulated * 1000 / elapsed);
|
||||||
|
};
|
||||||
|
|
||||||
|
Reporter.prototype.reset = function(){
|
||||||
|
this.samples = [];
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user