Merge pull request #3978 from Snarling/atExitFix

NETSCRIPT: FIX #2931 atExit now allows synchronous ns functions
This commit is contained in:
hydroflame 2022-08-23 12:27:43 -03:00 committed by GitHub
commit 67be694b68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,22 +52,24 @@ function killWorkerScriptByPid(pid: number): boolean {
return false;
}
function stopAndCleanUpWorkerScript(workerScript: WorkerScript): void {
if (typeof workerScript.atExit === "function") {
function stopAndCleanUpWorkerScript(ws: WorkerScript): void {
killNetscriptDelay(ws);
if (typeof ws.atExit === "function") {
try {
workerScript.atExit();
ws.env.stopFlag = false;
ws.atExit();
} catch (e: unknown) {
let message = e instanceof ScriptDeath ? e.errorMessage : String(e);
message = message.replace(/.*\|DELIMITER\|/, "");
dialogBoxCreate(
`Error trying to call atExit for script ${workerScript.name} on ${workerScript.hostname} ${
workerScript.scriptRef.args
} ${String(e)}`,
`Error trying to call atExit for script ${[ws.name, ...ws.args].join(" ")} on ${ws.hostname}\n ${message}`,
);
console.log(e);
}
workerScript.atExit = undefined;
ws.atExit = undefined;
}
workerScript.env.stopFlag = true;
killNetscriptDelay(workerScript);
removeWorkerScript(workerScript);
ws.env.stopFlag = true;
removeWorkerScript(ws);
}
/**