File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,12 @@ export function makeSocket() {
1212 */
1313export async function connect ( socket : Socket ) : Promise < void > {
1414 if ( socket . connected ) return ;
15- socket . connect ( ) ;
1615
17- return await new Promise < void > ( ( resolve ) =>
16+ const waiting = new Promise < void > ( ( resolve ) =>
1817 socket . once ( "connect" , ( ) => resolve ( ) )
1918 ) ;
19+ socket . connect ( ) ;
20+ await waiting ;
2021}
2122
2223/** websocketを切断する
@@ -25,14 +26,15 @@ export async function connect(socket: Socket): Promise<void> {
2526 */
2627export async function disconnect ( socket : Socket ) : Promise < void > {
2728 if ( socket . disconnected ) return ;
28- socket . disconnect ( ) ;
2929
30- return await new Promise < void > ( ( resolve ) => {
30+ const waiting = new Promise < void > ( ( resolve ) => {
3131 const onDisconnect = ( reason : Socket . DisconnectReason ) => {
3232 if ( reason !== "io client disconnect" ) return ;
3333 resolve ( ) ;
3434 socket . off ( "disconnect" , onDisconnect ) ;
3535 } ;
3636 socket . on ( "disconnect" , onDisconnect ) ;
3737 } ) ;
38+ socket . disconnect ( ) ;
39+ await waiting ;
3840}
You can’t perform that action at this time.
0 commit comments