Wait for disconnect before removing listeners on connection
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/net",
|
||||
"version": "0.0.30",
|
||||
"version": "0.0.31",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "Utilities for connecting with nostr relays.",
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user