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.

40 lines
620 B

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