Minor improvements to Netscript Port loading and unloading

This commit is contained in:
Olivier Gagnon 2022-09-22 23:55:16 -04:00
parent 0044761fd3
commit 2a0dd6b6f8
2 changed files with 4 additions and 11 deletions

@ -493,15 +493,10 @@ function getValidPort(ctx: NetscriptContext, port: number): IPort {
);
}
let iport = NetscriptPorts.get(port);
if (iport == null || !(iport instanceof Object)) {
NetscriptPorts.set(port, NetscriptPort());
if (!iport) {
iport = NetscriptPort();
NetscriptPorts.set(port, iport);
}
// Try again.
iport = NetscriptPorts.get(port);
if (iport == null || !(iport instanceof Object)) {
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
}
return iport;
}

@ -45,9 +45,7 @@ export function prestigeWorkerScripts(): void {
killWorkerScript(ws);
}
for (const [__, port] of NetscriptPorts.entries()) {
port.clear();
}
NetscriptPorts.clear();
WorkerScriptStartStopEventEmitter.emit();
workerScripts.clear();