Select Git revision
AnnotationBox.js
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
AbstractWorker.js 1.28 KiB
class AbstractWorker {
constructor() {
this.config = {};
var
ival = 1000,
timer,
cmds = [],
execRun = false;
var update = function() {
if (!!timer) self.clearTimeout(timer);
this.tick(function(result) {
self.postMessage(result);
});
if (ival > 0) timer = self.setTimeout(update, ival);
}.bind(this);
var exec = function() {
if (!!cmds.length) {
execRun = true;
var cmd = cmds.shift();
if (typeof this[cmd.cmd] == "function") {
this[cmd.cmd].apply(this,cmd.params);
} else {
exec();
}
} else {
execRun = false;
}
}.bind(this);
this.start = function() {
update();
exec();
}
this.stop = function() {
if (!!timer) self.clearTimeout(timer);
exec();
}
this.loadConfig = function(name) {
AJAX.request("../../panels/departure/config/"+name+".json").then(function(data) {
this.config = this.processConfig(data.response);
exec();
}.bind(this),function() {
exec();
});
}
self.onmessage = function(e) {
cmds.push(e.data);
if (!execRun) exec();
}.bind(this);
this.setSpeed = function(val) {
if (isNaN(val = parseInt(val))) {
val = 0;
}
ival = val;
}
}
tick(callback) {
callback({});
}
processConfig(config) {
return config;
}
}