@@ -53,19 +53,17 @@ export default class WSClient {
53
53
/**
54
54
* Promise of the current status switching.
55
55
*/
56
- private statusPromise : null | Promise < void > = null ;
56
+ private statusPromise = Promise . resolve ( ) ;
57
57
58
58
/**
59
59
* Resolve status at a later message.
60
60
*/
61
61
private statusResolve : null | ( ( status : 'on' | 'off' ) => void ) = null ;
62
62
63
63
private async toggleServerRoute ( status : 'on' | 'off' ) {
64
- if ( this . statusPromise !== null ) {
65
- await this . statusPromise ;
66
- return ;
67
- }
64
+ const { statusPromise } = this ;
68
65
this . statusPromise = ( async ( ) => {
66
+ await statusPromise . catch ( ( ) => { } ) ;
69
67
const response = new Promise < 'on' | 'off' > ( ( resolve ) => {
70
68
this . statusResolve = resolve ;
71
69
} ) ;
@@ -78,7 +76,7 @@ export default class WSClient {
78
76
throw new Error ( `Server failed to switch ${ status } ` ) ;
79
77
}
80
78
} ) ( ) ;
81
- await this . statusPromise ;
79
+ return this . statusPromise ;
82
80
}
83
81
84
82
bypassFetch ( ...fetchArgs : Parameters < typeof fetch > ) {
@@ -116,7 +114,6 @@ export default class WSClient {
116
114
}
117
115
this . statusResolve ( meta . to ) ;
118
116
this . statusResolve = null ;
119
- this . statusPromise = null ;
120
117
return ;
121
118
}
122
119
let body : Blob | undefined ;
0 commit comments