Adjust Ws .disconnect() logic to always clear auto-connect (#3749)

This commit is contained in:
Jaco
2021-07-09 06:14:30 +02:00
committed by GitHub
parent e13a7ff5a1
commit 445a080f7d
2 changed files with 9 additions and 8 deletions
+8 -8
View File
@@ -215,18 +215,18 @@ export class WsProvider implements ProviderInterface {
}
/**
* @description Manually disconnect from the connection, clearing autoconnect logic
* @description Manually disconnect from the connection, clearing auto-connect logic
*/
// eslint-disable-next-line @typescript-eslint/require-await
public async disconnect (): Promise<void> {
// switch off autoConnect, we are in manual mode now
this.#autoConnectMs = 0;
try {
assert(!isNull(this.#websocket), 'Cannot disconnect on a non-connected websocket');
// switch off autoConnect, we are in manual mode now
this.#autoConnectMs = 0;
// 1000 - Normal closure; the connection successfully completed
this.#websocket.close(1000);
if (this.#websocket) {
// 1000 - Normal closure; the connection successfully completed
this.#websocket.close(1000);
}
} catch (error) {
l.error(error);