GANG: Reuse one promise for ns.gang.nextUpdate() (#1068)

This commit is contained in:
LJ
2024-01-27 15:25:30 -07:00
committed by GitHub
parent 05295598a4
commit b6b4788845
2 changed files with 12 additions and 6 deletions
+5 -2
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 { GangResolvers } from "../Gang/Gang";
import { GangNextUpdate } from "../Gang/Gang";
import { Player } from "@player";
import { FactionName } from "@enums";
import { GangConstants } from "../Gang/data/Constants";
@@ -325,7 +325,10 @@ export function NetscriptGang(): InternalAPI<IGang> {
return Math.round(gang.storedCycles / 5) * 1000;
},
nextUpdate: () => () => {
return new Promise<number>((res) => GangResolvers.push(res));
if (!GangNextUpdate.promise) {
GangNextUpdate.promise = new Promise<number>((res) => (GangNextUpdate.resolver = res));
}
return GangNextUpdate.promise;
},
};
}