API: make ns.atExit add the callback to an array instead of setting it (#1059)

This commit is contained in:
Shy
2024-03-06 01:22:45 +01:00
committed by GitHub
parent 4f4c6fe7e5
commit 4aaf845fca
7 changed files with 38 additions and 22 deletions
+15 -8
View File
@@ -1708,14 +1708,21 @@ export const ns: InternalAPI<NSFull> = {
sinceInstall: Object.assign({}, Player.moneySourceA),
sinceStart: Object.assign({}, Player.moneySourceB),
}),
atExit: (ctx) => (f) => {
if (typeof f !== "function") {
throw helpers.errorMessage(ctx, "argument should be function");
}
ctx.workerScript.atExit = () => {
f();
}; // Wrap the user function to prevent WorkerScript leaking as 'this'
},
atExit:
(ctx) =>
(f, id = "default") => {
if (typeof f !== "function") {
throw helpers.errorMessage(ctx, "argument should be function");
}
if (typeof id !== "string") {
throw helpers.errorMessage(ctx, "id should be a string");
}
ctx.workerScript.atExit.set(id, () => {
f();
}); // Wrap the user function to prevent WorkerScript leaking as 'this'
},
mv: (ctx) => (_host, _source, _destination) => {
const hostname = helpers.string(ctx, "host", _host);
const server = helpers.getServer(ctx, hostname);