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); let iport = NetscriptPorts.get(port);
if (iport == null || !(iport instanceof Object)) { if (!iport) {
NetscriptPorts.set(port, NetscriptPort()); 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; return iport;
} }

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