Skip to content

Commit

Permalink
Add timeout for fetching server status
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargjhaveri committed Jan 8, 2025
1 parent e15cd68 commit 7cb544c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/client/ServerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export class ServerConnection {
}
}

getServerStatus = async (): Promise<ServerStatus> => {
getServerStatus = async (timeout: number = 10000): Promise<ServerStatus> => {
await this.lastServerStatusPromise
this.lastServerStatusPromise = this.fetchServerStatus();
this.lastServerStatusPromise = this.fetchServerStatus(timeout);

const status = await this.lastServerStatusPromise;

Expand All @@ -114,12 +114,13 @@ export class ServerConnection {
setTimeout(this.updateStatusLoop, 5000);
}

private fetchServerStatus = async (): Promise<ServerStatus> => {
private fetchServerStatus = async (timeout: number): Promise<ServerStatus> => {
try {
const res = await this.fetch(url.status, {
headers: {
'Content-Type': 'application/json'
},
signal: AbortSignal.timeout(timeout)
});

if (res.status !== 200) {
Expand Down

0 comments on commit 7cb544c

Please sign in to comment.