mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 16:52:55 +02:00
MISC: change all nextUpdates to use one Promise (#1069)
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Action } from "../Bladeburner/Action";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
import { Player } from "@player";
|
||||
import { Bladeburner, BladeburnerResolvers } from "../Bladeburner/Bladeburner";
|
||||
import { Bladeburner, BladeburnerPromise } from "../Bladeburner/Bladeburner";
|
||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||
import { BlackOperation } from "../Bladeburner/BlackOperation";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
@@ -329,8 +329,11 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return Math.round(bladeburner.storedCycles / 5) * 1000;
|
||||
},
|
||||
nextUpdate: () => () => {
|
||||
return new Promise<number>((res) => BladeburnerResolvers.push(res));
|
||||
nextUpdate: (ctx) => () => {
|
||||
checkBladeburnerAccess(ctx);
|
||||
if (!BladeburnerPromise.promise)
|
||||
BladeburnerPromise.promise = new Promise<number>((res) => (BladeburnerPromise.resolve = res));
|
||||
return BladeburnerPromise.promise;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Product } from "../Corporation/Product";
|
||||
import { Material } from "../Corporation/Material";
|
||||
import { Warehouse } from "../Corporation/Warehouse";
|
||||
import { Division } from "../Corporation/Division";
|
||||
import { Corporation, CorporationResolvers } from "../Corporation/Corporation";
|
||||
import { Corporation, CorporationPromise } from "../Corporation/Corporation";
|
||||
import { omit } from "lodash";
|
||||
import { setDeprecatedProperties } from "../utils/DeprecationHelper";
|
||||
import {
|
||||
@@ -800,7 +800,9 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
},
|
||||
nextUpdate: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return new Promise<CorpStateName>((res) => CorporationResolvers.push(res));
|
||||
if (!CorporationPromise.promise)
|
||||
CorporationPromise.promise = new Promise<CorpStateName>((res) => (CorporationPromise.resolve = res));
|
||||
return CorporationPromise.promise;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
placeOrder,
|
||||
cancelOrder,
|
||||
initStockMarket,
|
||||
StockMarketResolvers,
|
||||
StockMarketPromise,
|
||||
} from "../StockMarket/StockMarket";
|
||||
import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers";
|
||||
import { PositionType, OrderType, StockSymbol } from "@enums";
|
||||
@@ -415,7 +415,9 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
},
|
||||
nextUpdate: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
return new Promise<number>((res) => StockMarketResolvers.push(res));
|
||||
if (!StockMarketPromise.promise)
|
||||
StockMarketPromise.promise = new Promise<number>((res) => (StockMarketPromise.resolve = res));
|
||||
return StockMarketPromise.promise;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user