mirror of
https://github.com/luxfi/pics.git
synced 2026-10-30 15:22:15 +00:00
42 lines
753 B
JavaScript
42 lines
753 B
JavaScript
'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();
|
|
}
|
|
}
|
|
|
|
};
|