MISC: change all nextUpdates to use one Promise (#1069)

This commit is contained in:
Caldwell
2024-02-10 12:27:47 +01:00
committed by GitHub
parent fbc41d0278
commit 8c2a23f2ba
10 changed files with 59 additions and 39 deletions
+5 -6
View File
@@ -4,7 +4,7 @@ import type { GangMember } from "../Gang/GangMember";
import type { GangMemberTask } from "../Gang/GangMemberTask";
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { GangNextUpdate } from "../Gang/Gang";
import { GangPromise } from "../Gang/Gang";
import { Player } from "@player";
import { FactionName } from "@enums";
import { GangConstants } from "../Gang/data/Constants";
@@ -324,11 +324,10 @@ export function NetscriptGang(): InternalAPI<IGang> {
const gang = getGang(ctx);
return Math.round(gang.storedCycles / 5) * 1000;
},
nextUpdate: () => () => {
if (!GangNextUpdate.promise) {
GangNextUpdate.promise = new Promise<number>((res) => (GangNextUpdate.resolver = res));
}
return GangNextUpdate.promise;
nextUpdate: (ctx) => () => {
getGang(ctx);
if (!GangPromise.promise) GangPromise.promise = new Promise<number>((res) => (GangPromise.resolve = res));
return GangPromise.promise;
},
};
}