diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index c28fbb39c..f5463fd66 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -60,7 +60,7 @@ export function prestigeWorkerScripts(): void { // JS script promises need a little massaging to have the same guarantees as netscript // promises. This does said massaging and kicks the script off. It returns a promise // that resolves or rejects when the corresponding worker script is done. -function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Promise { +function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Promise { workerScript.running = true; // The name of the currently running netscript function, to prevent concurrent @@ -125,10 +125,10 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro // Note: the environment that we pass to the JS script only needs to contain the functions visible // to that script, which env.vars does at this point. - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { executeJSScript(player, workerScript.getServer().scripts, workerScript) .then(() => { - resolve(workerScript); + resolve(); }) .catch((e) => reject(e)); }).catch((e) => { @@ -155,7 +155,7 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro }); } -function startNetscript1Script(workerScript: WorkerScript): Promise { +function startNetscript1Script(workerScript: WorkerScript): Promise { const code = workerScript.code; workerScript.running = true; @@ -170,7 +170,7 @@ function startNetscript1Script(workerScript: WorkerScript): Promise | null = null; // Script's resulting promise + let scriptExecution: Promise | null = null; // Script's resulting promise if (workerScript.name.endsWith(".js") || workerScript.name.endsWith(".ns")) { scriptExecution = startNetscript2Script(player, workerScript); } else { @@ -562,8 +562,7 @@ function createAndAddWorkerScript( // Once the code finishes (either resolved or rejected, doesnt matter), set its // running status to false - scriptExecution.then(function (w: WorkerScript) { - if(w !== workerScript) console.error("!BUG! Wrong WorkerScript instance !BUG!") + scriptExecution.then(function () { workerScript.running = false; workerScript.env.stopFlag = true; // On natural death, the earnings are transfered to the parent if it still exists.