File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,12 @@ export function makeSocket() {
12
12
*/
13
13
export async function connect ( socket : Socket ) : Promise < void > {
14
14
if ( socket . connected ) return ;
15
- socket . connect ( ) ;
16
15
17
- return await new Promise < void > ( ( resolve ) =>
16
+ const waiting = new Promise < void > ( ( resolve ) =>
18
17
socket . once ( "connect" , ( ) => resolve ( ) )
19
18
) ;
19
+ socket . connect ( ) ;
20
+ await waiting ;
20
21
}
21
22
22
23
/** websocketを切断する
@@ -25,14 +26,15 @@ export async function connect(socket: Socket): Promise<void> {
25
26
*/
26
27
export async function disconnect ( socket : Socket ) : Promise < void > {
27
28
if ( socket . disconnected ) return ;
28
- socket . disconnect ( ) ;
29
29
30
- return await new Promise < void > ( ( resolve ) => {
30
+ const waiting = new Promise < void > ( ( resolve ) => {
31
31
const onDisconnect = ( reason : Socket . DisconnectReason ) => {
32
32
if ( reason !== "io client disconnect" ) return ;
33
33
resolve ( ) ;
34
34
socket . off ( "disconnect" , onDisconnect ) ;
35
35
} ;
36
36
socket . on ( "disconnect" , onDisconnect ) ;
37
37
} ) ;
38
+ socket . disconnect ( ) ;
39
+ await waiting ;
38
40
}
You can’t perform that action at this time.
0 commit comments