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
@@ -24,11 +24,11 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
signalCompletion = () => {
// Intentionally empty function, this is just an initial value and will never be used.
};
nextCompletion: Promise<void>;
nextCompletionPromise: Promise<void> | null;
constructor(params?: SleeveBladeburnerWorkParams) {
super();
this.nextCompletion = new Promise((r) => (this.signalCompletion = r));
this.nextCompletionPromise = null;
this.actionType = params?.type ?? "General";
this.actionName = params?.name ?? "Field Analysis";
}
@@ -40,7 +40,7 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
}
finish() {
this.signalCompletion();
if (this.nextCompletionPromise) this.signalCompletion();
}
process(sleeve: Sleeve, cycles: number) {
@@ -73,11 +73,13 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
this.tasksCompleted++;
this.cyclesWorked -= this.cyclesNeeded(sleeve);
// Resolve and reset nextCompletion promise
const resolver = this.signalCompletion;
this.nextCompletion = new Promise((r) => (this.signalCompletion = r));
resolver();
if (this.nextCompletionPromise) this.signalCompletion();
}
}
get nextCompletion(): Promise<void> {
if (!this.nextCompletionPromise) this.nextCompletionPromise = new Promise((r) => (this.signalCompletion = r));
return this.nextCompletionPromise;
}
APICopy(sleeve: Sleeve) {
return {