mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-21 13:45:44 +01:00
unasync trywriteport
This commit is contained in:
parent
aa80cf6451
commit
361466b7fa
@ -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) =>
|
||||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user