PORTS: Add ns.nextPortWrite() as a safer option (#1036)

This commit is contained in:
LJ
2024-01-15 04:10:39 -07:00
committed by GitHub
parent d0e66d5be2
commit 157ff8ea88
4 changed files with 20 additions and 5 deletions
+5 -1
View File
@@ -97,7 +97,7 @@ import { getBitNodeMultipliers } from "./BitNode/BitNode";
import { assert, arrayAssert, stringAssert, objectAssert } from "./utils/helpers/typeAssertion";
import { cloneDeep, escapeRegExp } from "lodash";
import numeral from "numeral";
import { clearPort, peekPort, portHandle, readPort, tryWritePort, writePort } from "./NetscriptPort";
import { clearPort, peekPort, portHandle, readPort, tryWritePort, writePort, nextPortWrite } from "./NetscriptPort";
import { FilePath, resolveFilePath } from "./Paths/FilePath";
import { hasScriptExtension } from "./Paths/ScriptFilePath";
import { hasTextExtension } from "./Paths/TextFilePath";
@@ -1373,6 +1373,10 @@ export const ns: InternalAPI<NSFull> = {
}
return tryWritePort(portNumber, data);
},
nextPortWrite: (ctx) => (_portNumber) => {
const portNumber = helpers.portNumber(ctx, _portNumber);
return nextPortWrite(portNumber);
},
readPort: (ctx) => (_portNumber) => {
const portNumber = helpers.portNumber(ctx, _portNumber);
return readPort(portNumber);