mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
API: Added spawnDelay parameter to ns.spawn options, allowing user defined delay (#807)
This commit is contained in:
@@ -45,6 +45,7 @@ export const helpers = {
|
||||
positiveInteger,
|
||||
scriptArgs,
|
||||
runOptions,
|
||||
spawnOptions,
|
||||
argsToString,
|
||||
makeBasicErrorMsg,
|
||||
makeRuntimeErrorMsg,
|
||||
@@ -72,13 +73,17 @@ export const helpers = {
|
||||
failOnHacknetServer,
|
||||
};
|
||||
|
||||
// RunOptions with non-optional, type-validated members, for passing between internal functions.
|
||||
/** RunOptions with non-optional, type-validated members, for passing between internal functions. */
|
||||
export interface CompleteRunOptions {
|
||||
threads: PositiveInteger;
|
||||
temporary: boolean;
|
||||
ramOverride?: number;
|
||||
preventDuplicates: boolean;
|
||||
}
|
||||
/** SpawnOptions with non-optional, type-validated members, for passing between internal functions. */
|
||||
export interface CompleteSpawnOptions extends CompleteRunOptions {
|
||||
spawnDelay: PositiveInteger;
|
||||
}
|
||||
|
||||
export function assertString(ctx: NetscriptContext, argName: string, v: unknown): asserts v is string {
|
||||
if (typeof v !== "string")
|
||||
@@ -207,6 +212,15 @@ function runOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteRun
|
||||
return result;
|
||||
}
|
||||
|
||||
function spawnOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteSpawnOptions {
|
||||
const result: CompleteSpawnOptions = { spawnDelay: 10000 as PositiveInteger, ...runOptions(ctx, threadOrOption) };
|
||||
if (typeof threadOrOption !== "object" || !threadOrOption) return result;
|
||||
// Safe assertion since threadOrOption type has been narrowed to a non-null object
|
||||
const { spawnDelay } = threadOrOption as Unknownify<CompleteSpawnOptions>;
|
||||
if (spawnDelay !== undefined) result.spawnDelay = positiveInteger(ctx, "spawnDelayMsec", spawnDelay);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Convert multiple arguments for tprint or print into a single string. */
|
||||
function argsToString(args: unknown[]): string {
|
||||
// Reduce array of args into a single output string
|
||||
|
||||
Reference in New Issue
Block a user