jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
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.
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require(__dirname+'/../lib/misc/config.js');
|
|
|
|
|
|
|
|
module.exports = class Schedule {
|
|
|
|
|
|
|
|
constructor (func, interval, immediate, condition) {
|
|
|
|
this.func = func;
|
|
|
|
this.interval = interval;
|
|
|
|
this.immediate = immediate;
|
|
|
|
this.condition = condition;
|
|
|
|
this.intervalId = null;
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//start the schedule
|
|
|
|
start () {
|
|
|
|
if (!this.intervalId) {
|
|
|
|
if (this.immediate) {
|
|
|
|
this.func();
|
|
|
|
}
|
|
|
|
this.intervalId = setInterval(this.func, this.interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//stop the schedule
|
|
|
|
stop () {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
this.intervalId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check config and either start or stop
|
|
|
|
update () {
|
|
|
|
if (!this.condition || config.get[this.condition]) {
|
|
|
|
this.start();
|
|
|
|
} else {
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|