mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
MISC: Make spawn able to have 0 delay (#1333)
This eliminates a hole where spawn was unrelaible, because other scripts could jump in and steal the RAM. It's not an API break, because 0 used to be an invalid value.
This commit is contained in:
@@ -93,7 +93,7 @@ export interface CompleteRunOptions {
|
||||
}
|
||||
/** SpawnOptions with non-optional, type-validated members, for passing between internal functions. */
|
||||
export interface CompleteSpawnOptions extends CompleteRunOptions {
|
||||
spawnDelay: PositiveInteger;
|
||||
spawnDelay: number;
|
||||
}
|
||||
/** HGWOptions with non-optional, type-validated members, for passing between internal functions. */
|
||||
export interface CompleteHGWOptions {
|
||||
@@ -189,11 +189,16 @@ function runOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteRun
|
||||
}
|
||||
|
||||
function spawnOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteSpawnOptions {
|
||||
const result: CompleteSpawnOptions = { spawnDelay: 10000 as PositiveInteger, ...runOptions(ctx, threadOrOption) };
|
||||
const result: CompleteSpawnOptions = { spawnDelay: 10000, ...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);
|
||||
if (spawnDelay !== undefined) {
|
||||
result.spawnDelay = number(ctx, "spawnDelay", spawnDelay);
|
||||
if (result.spawnDelay < 0) {
|
||||
throw errorMessage(ctx, `spawnDelay must be non-negative, got ${spawnDelay}`);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user