Implemented Hack and sleep in script. IMplemented functionality that allows scripts to stop (rejecting the Promises). Scripts will now automatically stop if they are not infinite. THIS IS UNTESTED TEST THIS WHEN I CAN. Still need to implement kill command

This commit is contained in:
Daniel Xie
2016-12-05 16:31:46 -06:00
parent 6d9f0669ba
commit 437ebc2703
6 changed files with 158 additions and 11 deletions
+30 -1
View File
@@ -20,7 +20,9 @@ var workerScripts = [];
//Loop through workerScripts and run every script that is not currently running
function runScriptsLoop() {
//Run any scripts that haven't been started
for (var i = 0; i < workerScripts.length; i++) {
//If it isn't running, start the script
if (workerScripts[i].running == false) {
var ast = Parser(Tokenizer(InputStream(workerScripts[i].code)));
@@ -29,7 +31,34 @@ function runScriptsLoop() {
console.log(ast);
workerScripts[i].running = true;
evaluate(ast, workerScripts[i]);
var p = evaluate(ast, workerScripts[i]);
//Once the code finishes (either resolved or rejected, doesnt matter), set its
//running status to false
p.then(function(foo) {
workerScripts[i].running = false;
}, function() {
workerScripts[i].running = false;
});
}
}
//Delete any scripts that finished or have been killed. Loop backwards bc removing
//items fucks up the indexing
for (var i = workerScripts.length - 1; i >= 0; i--) {
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == true) {
//Delete script from the runningScripts array on its host serverIp
var ip = workerScripts[i].serverIp;
var name = workerScripts[i].name;
for (var j = 0; j < AllServers[ip].runningScripts.length; j++) {
if (AllServers[ip].runningScripts[j] == name) {
AllServers[i].runningScripts.splice(j, 1);
break;
}
}
//Delete script from workerScripts
workerScripts.splice(i, 1);
}
}