Wait for disconnect before removing listeners on connection
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/net",
|
"name": "@welshman/net",
|
||||||
"version": "0.0.30",
|
"version": "0.0.31",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Utilities for connecting with nostr relays.",
|
"description": "Utilities for connecting with nostr relays.",
|
||||||
|
|||||||
@@ -117,15 +117,17 @@ export class Connection extends Emitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
async disconnect() {
|
||||||
this.socket.disconnect()
|
await this.socket.disconnect()
|
||||||
|
|
||||||
this.sender.clear()
|
this.sender.clear()
|
||||||
this.receiver.clear()
|
this.receiver.clear()
|
||||||
this.meta.clearPending()
|
this.meta.clearPending()
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
async destroy() {
|
||||||
this.disconnect()
|
await this.disconnect()
|
||||||
|
|
||||||
this.removeAllListeners()
|
this.removeAllListeners()
|
||||||
this.sender.stop()
|
this.sender.stop()
|
||||||
this.receiver.stop()
|
this.receiver.stop()
|
||||||
|
|||||||
@@ -115,10 +115,12 @@ export class ConnectionAuth {
|
|||||||
while (Date.now() < deadline) {
|
while (Date.now() < deadline) {
|
||||||
await sleep(100)
|
await sleep(100)
|
||||||
|
|
||||||
|
// State got reset while we were waiting
|
||||||
if ([None, Requested].includes(this.status)) {
|
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)) {
|
if ([DeniedSignature, Forbidden, Ok].includes(this.status)) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user