unasync trywriteport

This commit is contained in:
Snarling 2022-10-04 07:59:50 -04:00
parent aa80cf6451
commit 361466b7fa
3 changed files with 5 additions and 9 deletions

@ -51,11 +51,9 @@ Here is a summary of all rules you need to follow when writing Netscript JS code
* grow * grow
* weaken * weaken
* sleep * sleep
* asleep
* prompt * prompt
* wget * wget
* scp
* write
* writePort
* Any function that contains :code:`await` must be declared as :code:`async` * Any function that contains :code:`await` must be declared as :code:`async`
@ -147,9 +145,7 @@ You may have noticed that every new ns2 file will contains the following comment
.. code-block:: javascript .. code-block:: javascript
/** /** @param {NS} ns */
* @param {NS} ns
**/
This comment is used to help the text editor autocomplete functions in the Netscript API. You can enable it by pressing ctrl+space after `ns.` This comment is used to help the text editor autocomplete functions in the Netscript API. You can enable it by pressing ctrl+space after `ns.`

@ -1518,7 +1518,7 @@ const base: InternalAPI<NS> = {
}, },
tryWritePort: tryWritePort:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_port: unknown, data: unknown = ""): Promise<any> => { (_port: unknown, data: unknown = ""): boolean => {
const port = helpers.number(ctx, "port", _port); const port = helpers.number(ctx, "port", _port);
if (typeof data !== "string" && typeof data !== "number") { if (typeof data !== "string" && typeof data !== "number") {
throw helpers.makeRuntimeErrorMsg( throw helpers.makeRuntimeErrorMsg(
@ -1527,7 +1527,7 @@ const base: InternalAPI<NS> = {
); );
} }
const iport = helpers.getValidPort(ctx, port); const iport = helpers.getValidPort(ctx, port);
return Promise.resolve(iport.tryWrite(data)); return iport.tryWrite(data);
}, },
readPort: readPort:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>

@ -5969,7 +5969,7 @@ export interface NS {
* @param data - Data to write. * @param data - Data to write.
* @returns True if the data is successfully written to the port, and false otherwise. * @returns True if the data is successfully written to the port, and false otherwise.
*/ */
tryWritePort(port: number, data: string | number): Promise<boolean>; tryWritePort(port: number, data: string | number): boolean;
/** /**
* Read content of a file. * Read content of a file.