You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
782 B

6 years ago
const Cycle = require("./cycle").Cycle;
const logger = require("./logger");
class CycleBuffer {
constructor(purgeTime, fixed=false) {
6 years ago
this.time = purgeTime;
this.buffer=[];
var th = this;
this.onclear = function(sp) {};
if(fixed) {
this.fixed=true;
}
else {
this.inter = setInterval(function() {
th.purge();
}, this.time);
}
6 years ago
}
purge()
{
this.onclear(this);
this.buffer.length=0;
}
add(cycle) {
this.buffer.push(cycle);
if(this.fixed && this.buffer.length>=this.time)
this.buffer.shift();
6 years ago
}
all() {
var ret=[];
for(var i=0;i<this.buffer.length;i++)
{
ret.push(this.buffer[i]);
}
return ret;
}
close() {
if(this.inter)
clearInterval(this.inter);
6 years ago
this.buffer.length=0;
}
}
module.exports = CycleBuffer;