Skip to content

Commit 639e70e

Browse files
committed
fix(route): await last status resolve
1 parent cd4a6ea commit 639e70e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/WS/WSClient.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,17 @@ export default class WSClient {
5353
/**
5454
* Promise of the current status switching.
5555
*/
56-
private statusPromise: null | Promise<void> = null;
56+
private statusPromise = Promise.resolve();
5757

5858
/**
5959
* Resolve status at a later message.
6060
*/
6161
private statusResolve: null | ((status: 'on' | 'off') => void) = null;
6262

6363
private async toggleServerRoute(status: 'on' | 'off') {
64-
if (this.statusPromise !== null) {
65-
await this.statusPromise;
66-
return;
67-
}
64+
const { statusPromise } = this;
6865
this.statusPromise = (async () => {
66+
await statusPromise.catch(() => {});
6967
const response = new Promise<'on' | 'off'>((resolve) => {
7068
this.statusResolve = resolve;
7169
});
@@ -78,7 +76,7 @@ export default class WSClient {
7876
throw new Error(`Server failed to switch ${status}`);
7977
}
8078
})();
81-
await this.statusPromise;
79+
return this.statusPromise;
8280
}
8381

8482
bypassFetch(...fetchArgs: Parameters<typeof fetch>) {
@@ -116,7 +114,6 @@ export default class WSClient {
116114
}
117115
this.statusResolve(meta.to);
118116
this.statusResolve = null;
119-
this.statusPromise = null;
120117
return;
121118
}
122119
let body: Blob | undefined;

0 commit comments

Comments
 (0)