Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
fix: Startup signals not used correctly
Browse files Browse the repository at this point in the history
As the game start signal was `undefined` initially, it caused the promise race to complete instantly, breaking the entire wait loop approach.
  • Loading branch information
oliversalzburg committed Oct 13, 2022
1 parent 591df9c commit c7bb23a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/userscript/source/UserScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export class UserScript {
}

static async waitForGame(timeout = 30000): Promise<GamePage> {
const signals: Array<Promise<unknown>> = [sleep(2000)];

if (isNil(UserScript._gameStartSignal) && typeof dojo !== "undefined") {
UserScript._gameStartSignal = new Promise(resolve => {
UserScript._gameStartSignalResolver = resolve;
Expand All @@ -203,6 +205,10 @@ export class UserScript {
});
}

if (!isNil(UserScript._gameStartSignal)) {
signals.push(UserScript._gameStartSignal);
}

if (timeout < 0) {
throw new Error("Unable to find game page. Giving up.");
}
Expand All @@ -213,7 +219,7 @@ export class UserScript {

cdebug(`Waiting for game... (timeout: ${Math.round(timeout / 1000)}s)`);

await Promise.race([UserScript._gameStartSignal, sleep(2000)]);
await Promise.race(signals);
return UserScript.waitForGame(timeout - 2000);
}

Expand Down

0 comments on commit c7bb23a

Please sign in to comment.