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.
This commit is contained in:
MageKing17 2021-07-02 14:31:07 -07:00 committed by danielyxie
parent ae15914efa
commit 30abcec74a

@ -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);
}