From 30abcec74a4313b82486f8f777d1baa83d48d07f Mon Sep 17 00:00:00 2001 From: MageKing17 Date: Fri, 2 Jul 2021 14:31:07 -0700 Subject: [PATCH] Update scriptScheduler.ns example to not be pointlessly async. The example code gives the impression that `ns.run` and `ns.exec` are asynchronous, when they're not; making these functions async is adding overhead for no purpose. --- doc/source/netscript/netscriptjs.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/source/netscript/netscriptjs.rst b/doc/source/netscript/netscriptjs.rst index 4ddea3a1c..00927865e 100644 --- a/doc/source/netscript/netscriptjs.rst +++ b/doc/source/netscript/netscriptjs.rst @@ -159,18 +159,21 @@ importing other NetscriptJS scripts:: this.args = params.args ? params.args : []; } - ScriptJob.prototype.run = async function(ns) { + ScriptJob.prototype.run = function(ns) { let runArgs = [this.fn, this.threads].concat(this.args); - await ns.run.apply(this, runArgs); + if (!ns.run.apply(this, runArgs)) { + throw new Error("Unable to run " + this.fn + " on " +ns.getHostname()); + } tprintColored("Running " + this.fn + " on " + ns.getHostname(), "blue"); } - ScriptJob.prototype.exec = async function(ns, target) { + ScriptJob.prototype.exec = function(ns, target) { ns.scp(this.fn, target); let execArgs = [this.fn, target, this.threads].concat(this.args); - await ns.exec.apply(this, execArgs); - + if (!ns.exec.apply(this, execArgs)) { + throw new Error("Unable to execute " + this.fn + " on " + target); + } tprintColored("Executing " + this.fn + " on " + target, "blue"); } @@ -182,8 +185,8 @@ importing other NetscriptJS scripts:: threads: 1, args: ["foodnstuff"] }); - await job.run(ns); - await job.exec(ns, "foodnstuff"); + job.run(ns); + job.exec(ns, "foodnstuff"); } catch (e) { ns.tprint("Exception thrown in scriptScheduler.ns: " + e); }