Fix atExit loop

atExit clears itself from the WorkerScript before being executed.
This commit is contained in:
omuretsu 2023-02-23 08:39:47 -05:00
parent 3c7b0622a5
commit 37d2f57e53

@ -66,11 +66,12 @@ function stopAndCleanUpWorkerScript(ws: WorkerScript): void {
if (typeof ws.atExit === "function") {
try {
ws.env.stopFlag = false;
ws.atExit();
const atExit = ws.atExit;
ws.atExit = undefined;
atExit();
} catch (e: unknown) {
handleUnknownError(e, ws, "Error running atExit function.\n\n");
}
ws.atExit = undefined;
}
ws.env.stopFlag = true;
removeWorkerScript(ws);