Select Git revision
Forked from
FS Info TU Dortmund / Infoscreen / Infoscreen
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Worker.js 1.27 KiB
self.interval = self.interval || 1000;
self.tick = self.tick || function() {};
self.config = self.config || {};
(new function() {
var
me = this,
timer,
cmds = [],
execRun = false;
function update() {
if (!!timer) self.clearTimeout(timer);
self.tick(function(result) {
self.postMessage(result);
});
timer = self.setTimeout(update, self.interval);
}
function exec() {
if (!!cmds.length) {
execRun = true;
var cmd = cmds.shift();
me[cmd.cmd].apply(this,cmd.params);
} else {
execRun = false;
}
}
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) {
config = data.response;
if (isObject(config) && isArrayNotEmpty(config['stops'])) {
config['stops_converted'] = [];
for (var i = 0; i < config['stops'].length; ++i) {
config['stops_converted'].push({url:'http://vrrf.finalrewind.org/'+config['stops'][i].split(':').join('/')+'.json',method:'GET',params:{frontend:'json'}});
}
}
exec();
},function() {
exec();
});
}
self.onmessage = function(e) {
cmds.push(e.data);
if (!execRun) exec();
}.bind(this);
}());