File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export class FireFlyWebSocket {
26
26
private readonly logger = new Logger ( FireFlyWebSocket . name ) ;
27
27
28
28
private socket ?: WebSocket ;
29
- private closed = false ;
29
+ private closed ? = ( ) => { } ;
30
30
private pingTimer ?: NodeJS . Timeout ;
31
31
private disconnectTimer ?: NodeJS . Timeout ;
32
32
private reconnectTimer ?: NodeJS . Timeout ;
@@ -61,7 +61,7 @@ export class FireFlyWebSocket {
61
61
auth,
62
62
handshakeTimeout : this . options . heartbeatInterval ,
63
63
} ) ) ;
64
- this . closed = false ;
64
+ this . closed = undefined ;
65
65
66
66
socket
67
67
. on ( 'open' , ( ) => {
@@ -177,15 +177,18 @@ export class FireFlyWebSocket {
177
177
}
178
178
}
179
179
180
- close ( ) {
181
- this . closed = true ;
180
+ async close ( wait ?: boolean ) : Promise < void > {
181
+ const closedPromise = new Promise < void > ( resolve => {
182
+ this . closed = resolve ;
183
+ } ) ;
182
184
this . clearPingTimers ( ) ;
183
185
if ( this . socket ) {
184
186
try {
185
187
this . socket . close ( ) ;
186
188
} catch ( e : any ) {
187
189
this . logger . warn ( `Failed to clean up websocket: ${ e . message } ` ) ;
188
190
}
191
+ if ( wait ) await closedPromise ;
189
192
this . socket = undefined ;
190
193
}
191
194
}
You can’t perform that action at this time.
0 commit comments