mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user