Wait for disconnect before removing listeners on connection

This commit is contained in:
Jon Staab
2024-10-30 13:26:04 -07:00
parent da3379bca3
commit c93d102c08
3 changed files with 10 additions and 6 deletions
+6 -4
View File
@@ -117,15 +117,17 @@ export class Connection extends Emitter {
}
}
disconnect() {
this.socket.disconnect()
async disconnect() {
await this.socket.disconnect()
this.sender.clear()
this.receiver.clear()
this.meta.clearPending()
}
destroy() {
this.disconnect()
async destroy() {
await this.disconnect()
this.removeAllListeners()
this.sender.stop()
this.receiver.stop()
+3 -1
View File
@@ -115,10 +115,12 @@ export class ConnectionAuth {
while (Date.now() < deadline) {
await sleep(100)
// State got reset while we were waiting
if ([None, Requested].includes(this.status)) {
throw new Error("Auth flow reset while waiting for auth")
break
}
// We've completed the auth flow
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
break
}