API: Added spawnDelay parameter to ns.spawn options, allowing user defined delay (#807)

This commit is contained in:
muesli4brekkies
2023-09-27 06:31:47 +01:00
committed by GitHub
parent 7fad6e0778
commit c5e2f65cb0
10 changed files with 78 additions and 26 deletions
+3 -4
View File
@@ -746,9 +746,8 @@ export const ns: InternalAPI<NSFull> = {
(ctx) =>
(_scriptname, _thread_or_opt = 1, ..._args) => {
const path = helpers.scriptPath(ctx, "scriptname", _scriptname);
const runOpts = helpers.runOptions(ctx, _thread_or_opt);
const runOpts = helpers.spawnOptions(ctx, _thread_or_opt);
const args = helpers.scriptArgs(ctx, _args);
const spawnDelay = 10;
setTimeout(() => {
const scriptServer = GetServer(ctx.workerScript.hostname);
if (scriptServer == null) {
@@ -756,9 +755,9 @@ export const ns: InternalAPI<NSFull> = {
}
return runScriptFromScript("spawn", scriptServer, path, args, ctx.workerScript, runOpts);
}, spawnDelay * 1e3);
}, runOpts.spawnDelay);
helpers.log(ctx, () => `Will execute '${path}' in ${spawnDelay} seconds`);
helpers.log(ctx, () => `Will execute '${path}' in ${runOpts.spawnDelay} seconds`);
if (killWorkerScript(ctx.workerScript)) {
helpers.log(ctx, () => "Exiting...");